0
votes

We have asp.net core based docker containers trying to connect to MongoDB atlas with the C# driver version 2.4.3.

The connection is working fine for when we run it outside the container. i.e. directly from kestrel. But when the same code is run from within a container, the connection to mongodb atlas times out.

Details: MongoDB C# Driver version: 2.4.3

Connection String: mongodb://sa:@cluster0-shard-00-00-po5vp.mongodb.net:27017,cluster0-shard-00-01-po5vp.mongodb.net:27017,cluster0-shard-00-02-po5vp.mongodb.net:27017/admin?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin

Database to be accessed: Configurations

ASP.net Core version: 1.1

BaseImage in Dockerfile: microsoft/aspnetcore-build

Dockerfile contents: FROM microsoft/aspnetcore-build WORKDIR /SaaS_Configuration_Microservice COPY ./SaaS_Configuration_Microservice . EXPOSE 80 RUN dotnet restore RUN dotnet publish -c Release -o PublishOutput ENTRYPOINT ["dotnet", "PublishOutput/SaaS_Configuration_Microservice.dll"]

We are running kestrel in Windows 10.

Complete Error Message: ex.Message "A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = ReadPreferenceServerSelector{ ReadPreference = { Mode : Primary } }, 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/cluster0-shard-00-00-po5vp.mongodb.net:27017\" }\", EndPoint: \"Unspecified/cluster0-shard-00-00-po5vp.mongodb.net:27017\", State: \"Disconnected\", Type: \"Unknown\", HeartbeatException: \"MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server. ---> MongoDB.Driver.MongoCommandException: Command failed.\n at MongoDB.Driver.Core.WireProtocol.CommandWireProtocol1.ProcessReply(ConnectionId connectionId, ReplyMessage1 reply)\n at MongoDB.Driver.Core.WireProtocol.CommandWireProtocol1.<ExecuteAsync>d__11.MoveNext()\n--- End of stack trace from previous location where exception was thrown ---\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\n at MongoDB.Driver.Core.Connections.ConnectionInitializer.<InitializeConnectionAsync>d__3.MoveNext()\n--- End of stack trace from previous location where exception was thrown ---\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\n at MongoDB.Driver.Core.Connections.BinaryConnection.<OpenHelperAsync>d__48.MoveNext()\n --- End of inner exception stack trace ---\n at MongoDB.Driver.Core.Connections.BinaryConnection.<OpenHelperAsync>d__48.MoveNext()\n--- End of stack trace from previous location where exception was thrown ---\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\n at MongoDB.Driver.Core.Servers.ServerMonitor.<HeartbeatAsync>d__27.MoveNext()\" }, { ServerId: \"{ ClusterId : 1, EndPoint : \"Unspecified/cluster0-shard-00-01-po5vp.mongodb.net:27017\" }\", EndPoint: \"Unspecified/cluster0-shard-00-01-po5vp.mongodb.net:27017\", State: \"Disconnected\", Type: \"Unknown\", HeartbeatException: \"MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server. ---> MongoDB.Driver.MongoCommandException: Command failed.\n at MongoDB.Driver.Core.WireProtocol.CommandWireProtocol1.ProcessReply(ConnectionId connectionId, ReplyMessage1 reply)\n at MongoDB.Driver.Core.WireProtocol.CommandWireProtocol1.d__11.MoveNext()\n--- End of stack trace from previous location where exception was thrown ---\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\n at MongoDB.Driver.Core.Connections.ConnectionInitializer.d__3.MoveNext()\n--- End of stack trace from previous location where exception was thrown ---\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\n at MongoDB.Driver.Core.Connections.BinaryConnection.d__48.MoveNext()\n --- End of inner exception stack trace ---\n at MongoDB.Driver.Core.Connections.BinaryConnection.d__48.MoveNext()\n--- End of stack trace from previous location where exception was thrown ---\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\n at MongoDB.Driver.Core.Servers.ServerMonitor.d__27.MoveNext()\" }, { ServerId: \"{ ClusterId : 1, EndPoint : \"Unspecified/cluster0-shard-00-02-po5vp.mongodb.net:27017\" }\", EndPoint: \"Unspecified/cluster0-shard-00-02-po5vp.mongodb.net:27017\", State: \"Disconnected\", Type: \"Unknown\", HeartbeatException: \"MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server. ---> MongoDB.Driver.MongoCommandException: Command failed.\n at MongoDB.Driver.Core.WireProtocol.CommandWireProtocol1.ProcessReply(ConnectionId connectionId, ReplyMessage1 reply)\n at MongoDB.Driver.Core.WireProtocol.CommandWireProtocol`1.d__11.MoveNext()\n--- End of stack trace from previous location where exception was thrown ---\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\n at MongoDB.Driver.Core.Connections.ConnectionInitializer.d__3.MoveNext()\n--- End of stack trace from previous location where exception was thrown ---\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\n at MongoDB.Driver.Core.Connections.BinaryConnection.d__48.MoveNext()\n --- End of inner exception stack trace ---\n at MongoDB.Driver.Core.Connections.BinaryConnection.d__48.MoveNext()\n--- End of stack trace from previous location where exception was thrown ---\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\n at MongoDB.Driver.Core.Servers.ServerMonitor.d__27.MoveNext()\" }] }." string

Inner exception: null

1
Ping to google and cloud.mongodb.com is working fine from inside the container.Aviral Bajpai

1 Answers

1
votes

"microsoft/aspnetcore-build" is a Linux image and there is a bug: https://docs.atlas.mongodb.com/driver-connection/#c-net-driver-example

IMPORTANT The .NET Core library does not support the SNI TLS extension on Linux and OSX. Applications using .NET Core on these operating systems cannot connect to a Atlas Free Tier cluster.

The issue is tracked on the dotnet/corefx github page.