Hi,
When a try to connect a dockerized application ussing the .net driver 3.4.x into a mongodb server 8.0.3 also dockerized and configured as replicaset the driver has a timeout and it can’t connect to the mongo server.
If i use a dockerized mongo server that is not replica set or the same dockerized application with driver 2.30.0 the application can connect to the mongo server.
The error when mongo server is configured as replica set
LogRecord.Exception: System.TimeoutException: A timeout occurred after 30000ms selecting a server using CompositeServerSelector{ Selectors = ReadPreferenceServerSelector{ ReadPreference = { Mode : Primary } }, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 }, OperationsCountServerSelector }. Client view of cluster state is { ClusterId : “1”, Type : “Unknown”, State : “Connected”, Servers : [{ ServerId: “{ ClusterId : 1, EndPoint : “Unspecified/mongodb:27017” }”, EndPoint: “Unspecified/mongodb:27017”, ReasonChanged: “Heartbeat”, State: “Connected”, ServerVersion: 8.0.0, TopologyVersion: { “processId” : { “$oid” : “688ce4d50ca1a2ea3f747bae” }, “counter” : 0 }, Type: “ReplicaSetGhost”, WireVersionRange: “[0, 25]”, LastHeartbeatTimestamp: “2025-08-01T16:03:45.4218373Z”, LastUpdateTimestamp: “2025-08-01T16:03:45.4218387Z” }] }.
2025-08-01T16:03:55.437806989Z at MongoDB.Driver.Core.Clusters.Cluster.ThrowTimeoutException(IServerSelector selector, ClusterDescription description)
2025-08-01T16:03:55.437808621Z at MongoDB.Driver.Core.Clusters.Cluster.WaitForDescriptionChangedHelper.HandleCompletedTask(Task completedTask)
2025-08-01T16:03:55.437809603Z at MongoDB.Driver.Core.Clusters.Cluster.WaitForDescriptionChangedAsync(IServerSelector selector, ClusterDescription description, Task descriptionChangedTask, TimeSpan timeout, CancellationToken cancellationToken)
2025-08-01T16:03:55.437810613Z at MongoDB.Driver.Core.Clusters.Cluster.SelectServerAsync(IServerSelector selector, CancellationToken cancellationToken)
2025-08-01T16:03:55.437811605Z at MongoDB.Driver.Core.Clusters.IClusterExtensions.SelectServerAndPinIfNeededAsync(IClusterInternal cluster, ICoreSessionHandle session, IServerSelector selector, IReadOnlyCollection1 deprioritizedServers, CancellationToken cancellationToken) 2025-08-01T16:03:55.437812620Z at MongoDB.Driver.Core.Bindings.ReadPreferenceBinding.GetReadChannelSourceAsync(IReadOnlyCollection
1 deprioritizedServers, CancellationToken cancellationToken)
2025-08-01T16:03:55.437813547Z at MongoDB.Driver.Core.Operations.RetryableReadContext.InitializeAsync(CancellationToken cancellationToken)
2025-08-01T16:03:55.437814720Z at MongoDB.Driver.Core.Operations.RetryableReadContext.CreateAsync(IReadBinding binding, Boolean retryRequested, CancellationToken cancellationToken)
2025-08-01T16:03:55.437815621Z at MongoDB.Driver.Core.Operations.FindOperation1.ExecuteAsync(IReadBinding binding, CancellationToken cancellationToken) 2025-08-01T16:03:55.437816479Z at MongoDB.Driver.OperationExecutor.ExecuteReadOperationAsync[TResult](IReadBinding binding, IReadOperation
1 operation, CancellationToken cancellationToken)
2025-08-01T16:03:55.437817357Z at MongoDB.Driver.MongoCollectionImpl1.ExecuteReadOperationAsync[TResult](IClientSessionHandle session, IReadOperation
1 operation, ReadPreference readPreference, CancellationToken cancellationToken)
2025-08-01T16:03:55.437826757Z at MongoDB.Driver.MongoCollectionImpl1.UsingImplicitSessionAsync[TResult](Func
2 funcAsync, CancellationToken cancellationToken)
With driver 2.30.0 and 3.4.2 this configuration works fine for a dockerize app
services:
MongoDB
mongodb:
image: mongo:8.0.3
container_name: tenant-management-mongodb
restart: unless-stopped
ports:
- “27017:27017”
With this configuration the dokerize app only works with driver 2.30.0
services:
MongoDB
mongodb:
image: mongo:8.0.3
command: mongod --replSet rs-local
container_name: tenant-management-mongodb
restart: unless-stopped
ports:
- “27017:27017”
Please, any suggestion?