[CSHARP-1167] Fail to connect to single node replication set Created: 22/Jan/15  Updated: 16/Nov/21  Resolved: 04/Apr/15

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

Type: Task Priority: Major - P3
Reporter: Richard Chen Assignee: Unassigned
Resolution: Done Votes: 0
Labels: question
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

jTry to connect to single node replication set. It times out after 30 seconds.
Repro with self hosted single node replication set. Server version: 2.8-rc4.
Repro with a free tier on mongolab.com. Server version:2.8-rc4

Not repro with below build:
commit: '17f6aa690f717c34fe2eaec06b13c8863fa4febc', commitDate: '2015-01-13 11:41:51' "

Suspected it was related to :
commit 4efda752fdea47acbfdbc58ba88dbd7cfd8e63ef
Author: rstam <robert@robertstam.org>
Date: Wed Jan 14 23:09:23 2015 -0500
CSHARP-1160: Enforce the distinction between Standalone and Direct.

Call stack:

Unhandled Exception: System.AggregateException: One or more errors occurred. ---> System.TimeoutException: Operation timed out after 00:00:30. ---> System.OperationCanceledException: The operation was canceled.
   at System.Threading.CancellationToken.ThrowOperationCanceledException()
   at MongoDB.Driver.Core.Clusters.Cluster.<WaitForDescriptionChangedAsync>d__1a.MoveNext() in c:\git\mongo-csharp-driver\src\MongoDB.Driver.Core\Core\Clusters\Cluster.cs:line 0
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MongoDB.Driver.Core.Clusters.Cluster.<SelectServerAsync>d__8.MoveNext() in c:\git\mongo-csharp-driver\src\MongoDB.Driver.Core\Core\Clusters\Cluster.cs:line 252
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MongoDB.Driver.Core.Bindings.ReadPreferenceBinding.<GetReadChannelSourceAsync>d__0.MoveNext() in c:\git\mongo-csharp-driver\src\MongoDB.Driver.Core\Core\Bindings\ReadPreferenceBinding.cs:line 51
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at MongoDB.Driver.Core.Operations.FindOperation`1.<ExecuteAsync>d__2.MoveNext() in c:\git\mongo-csharp-driver\src\MongoDB.Driver.Core\Core\Operations\FindOperation.cs:line 202
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MongoDB.Driver.OperationExecutor.<ExecuteReadOperationAsync>d__0`1.MoveNext() in c:\git\mongo-csharp-driver\src\MongoDB.Driver\OperationExecutor.cs:line 0
   --- End of inner exception stack trace ---
   at MongoDB.Driver.OperationExecutor.<ExecuteReadOperationAsync>d__0`1.MoveNext() in c:\git\mongo-csharp-driver\src\MongoDB.Driver\OperationExecutor.cs:line 43
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MongoDB.Driver.MongoCollectionImpl`1.<ExecuteReadOperation>d__47`1.MoveNext() in c:\git\mongo-csharp-driver\src\MongoDB.Driver\MongoCollectionImpl.cs:line 0
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MongoDB.Driver.IAsyncCursorSourceExtensions.<ToListAsync>d__14`1.MoveNext() in c:\git\mongo-csharp-driver\src\MongoDB.Driver.Core\IAsyncCursorSource.cs:line 63
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at mdbclient_cs.Program.<Run>d__0.MoveNext() in c:\dev\mdbclient\mdbclient-cs\Program.cs:line 31
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task.Wait()
   at mdbclient_cs.Program.Main(String[] args) in c:\dev\mdbclient\mdbclient-cs\Program.cs:line 16

Code:

            var cnnString = "mongodb://<useName>:<pwd>@dsxxx.mongolab.com:53617/db01";
 
            var mongoUrl = new MongoUrl(cnnString);
            var client = new MongoClient(mongoUrl);
            var database = client.GetDatabase(mongoUrl.DatabaseName);
            var collection = database.GetCollection<BsonDocument>("Users");
            var list = await collection.Find(new BsonDocument("Name", "Jack"))
                .ToListAsync();
            foreach (var document in list)
            {
                Console.WriteLine(document["Name"]);
            }



 Comments   
Comment by Richard Chen [ 23/Jan/15 ]

Thanks Robert.
With your modified connection string, the connection to mongolab.com went through successfully. but still failed with my self hosted single node replication set.

I agree that single node in Production is rare, but in dev/test environment, sometimes people are using it.
For people to use MMS backup feature, replicate set is required, and in some dev/test and non-critical scenarios, single node is a cheaper option. So single node replication set is a valid scenario.

-Richard

Comment by Robert Stam [ 22/Jan/15 ]

A connection string with a single host implies that the server must be either a standalone server or shard router.

A replica set with a single node is an unusual case. You can specify on the connection string that the single server is expected to be a replica set in either of the following ways:

mongodb://hostname/?connect=replicaset
mongodb://hostname/?replicaset=name

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