-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
None
-
Affects Version/s: 2.9.0, 2.10.4
-
Component/s: Connectivity
-
Labels:None
-
Environment:linux docker
Hello, I have a .net core program run in linux docker container. When I run the program in docker , the program fail to connect mongodb with replica set due to serverselectiontimeout. and it report below errors. We set a long time out 3-4 minutes, it could be connected. But too slow to connect mongodb. If I run in linux using dotnet run, the program is normal without connection issue. The issue born us a long time. Any solutions? how to resolve the issue?
/////////////////////////////////////////////////////////////////////////////////
Environment info:
Mongodb driver version 2.10.4, actually, we try from 2.9.0 to 2.10.4, neither one works
Mongodb version 4.2
.Net core version 3.1
Linux version: centos-release-7-7.1908.0.el7.centos.x86_64
Docker version: we try on 18.09.6, build 481bc77156 and 19.03.5, build 633a0ea
/////////////////////////////////////////////////////////////////////////////////
Error message:
System.TimeoutException: A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = MongoDB.Driver.MongoClient+AreSessionsSupportedServerSelector, LatencyLimitingServerSelector
{ AllowedLatencyRange = 00:00:00.0150000 }}. Client view of cluster state is { ClusterId : "1", ConnectionMode : "ReplicaSet", Type : "ReplicaSet", State : "Disconnected", Servers : [{ ServerId: "
{ ClusterId : 1, EndPoint : "Unspecified/ serverFQN:29031" }", EndPoint: "Unspecified/serverFQN:29031", State: "Disconnected", Type: "Unknown", LastUpdateTimestamp: "2020-05-06T08:50:17.7201620Z" }, { ServerId: "
{ ClusterId : 1, EndPoint : "Unspecified/serverFQN:29032" }", EndPoint: "Unspecified/serverFQN:29032", State: "Disconnected", Type: "Unknown", LastUpdateTimestamp: "2020-05-06T08:50:17.7260395Z" }, { ServerId: "
{ ClusterId : 1, EndPoint : "Unspecified/serverFQN:29033" }", EndPoint: "Unspecified/ serverFQN:29033", State: "Disconnected", Type: "Unknown", LastUpdateTimestamp: "2020-05-06T08:50:17.7265232Z" }] }.
at MongoDB.Driver.Core.Clusters.Cluster.ThrowTimeoutException(IServerSelector selector, ClusterDescription description)
at MongoDB.Driver.Core.Clusters.Cluster.WaitForDescriptionChangedHelper.HandleCompletedTask(Task completedTask)
at MongoDB.Driver.Core.Clusters.Cluster.WaitForDescriptionChanged(IServerSelector selector, ClusterDescription description, Task descriptionChangedTask, TimeSpan timeout, CancellationToken cancellationToken)
at MongoDB.Driver.Core.Clusters.Cluster.SelectServer(IServerSelector selector, CancellationToken cancellationToken)
at MongoDB.Driver.MongoClient.AreSessionsSupportedAfterServerSelection(CancellationToken cancellationToken)
at MongoDB.Driver.MongoClient.AreSessionsSupported(CancellationToken cancellationToken)
at MongoDB.Driver.MongoClient.StartImplicitSession(CancellationToken cancellationToken)
at MongoDB.Driver.OperationExecutor.StartImplicitSession(CancellationToken cancellationToken)
at MongoDB.Driver.MongoCollectionImpl`1.UsingImplicitSession[TResult](Func`2 func, CancellationToken cancellationToken)
at MongoDB.Driver.MongoCollectionImpl`1.FindSync[TProjection](FilterDefinition`1 filter, FindOptions`2 options, CancellationToken cancellationToken)
at MongoDB.Driver.FindFluent`2.ToCursor(CancellationToken cancellationToken)
at MongoDB.Driver.IAsyncCursorSourceExtensions.ToList[TDocument](IAsyncCursorSource`1 source, CancellationToken cancellationToken)
at PwC.Ms.Console.Program.Main(String[] args) in /src/console/Program.cs:line 81
///////////////////////////////////////////////////////////////////////////////////
Sample code we used when connect mongodb:
var clientSettings = MongoClientSettings.FromConnectionString(url);
if (requireSsl)
{
clientSettings.SslSettings = new SslSettings
;
clientSettings.VerifySslCertificate = false;
clientSettings.UseSsl = true;
clientSettings.AllowInsecureTls = true;
}
try
catch (Exception e)
{ System.Console.WriteLine(e); }
///////////////////////////////////////////////////////////////////////////////////
docker file content:
FROM mcr.microsoft.com/dotnet/core/runtime:3.1-buster-slim AS base
WORKDIR /app
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["console/Ms.Console.csproj", "console/"]
RUN dotnet restore "console/Ms.Console.csproj"
COPY . .
WORKDIR "/src/console"
RUN dotnet build "Ms.Console.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Ms.Console.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Ms.Console.dll"]