[CSHARP-2018] 2.3.0 driver does not honor ConnectTimeout setting Created: 19/Jul/17  Updated: 27/Oct/23  Resolved: 19/Jul/17

Status: Closed
Project: C# Driver
Component/s: Connectivity
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Raphael Londner Assignee: Robert Stam
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows Server 2012, Visual Studio 2017 Preview, Azure Functions



 Description   

I setting the ConnectTimeout property with the following code:

MongoUrl mongoUrl = new MongoUrl(strMongoDBAtlasUri);
var settings = MongoClientSettings.FromUrl(mongoUrl);
settings.ConnectTimeout = new System.TimeSpan(0, 0, 5);
var client = new MongoClient(settings);

while using a MongoDB Atlas URI (strMongoDBAtlasUri above).

I purposely provide incorrect user credentials in the Uri, but the exception is still thrown after 30 seconds (default value) instead of the 5 seconds I specified above.

The error message is the following:

Message "A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = WritableServerSelector, 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-nebpx.mongodb.net:27017\" }

\", EndPoint: \"Unspecified/cluster0-shard-00-00-nebpx.mongodb.net:27017\", State: \"Disconnected\", Type: \"Unknown\", HeartbeatException: \"MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server. --> MongoDB.Driver.MongoAuthenticationException: Unable to authenticate using sasl protocol mechanism SCRAM-SHA-1. ---> MongoDB.Driver.MongoCommandException: Command saslStart failed: Authentication failed..\r\n at MongoDB.Driver.Core.WireProtocol.CommandWireProtocol`1.ProcessReply(ConnectionId connectionId, ReplyMessage`1 reply)\r\n at MongoDB.Driver.Core.WireProtocol.CommandWireProtocol`1.<ExecuteAsync>d_11.MoveNext()\r\n-- End of stack trace from previous location where exception was thrown --\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at MongoDB.Driver.Core.Authentication.SaslAuthenticator.<AuthenticateAsync>d7.MoveNext()\r\n — End of inner exception stack trace ---\r\n at MongoDB.Driver.Core.Authentication.SaslAuthenticator.<AuthenticateAsync>d_7.MoveNext()\r\n-- End of stack trace from previous location where exception was thrown ---\r\n at



 Comments   
Comment by Raphael Londner [ 19/Jul/17 ]

I have verified that ServerSelectiontimeout works and should be used in this case. This ticket can be closed now.

Generated at Wed Feb 07 21:41:23 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.