[CSHARP-500] If host names in replica set connection string are aliases of the host names in the replica set config connection fails the first time Created: 15/Jun/12  Updated: 20/Mar/14  Resolved: 20/Jul/12

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

Type: Bug Priority: Major - P3
Reporter: Robert Stam Assignee: Craig Wilson
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by CSHARP-549 Connection string with multiple hosts... Closed
Related
is related to CSHARP-519 Support load balancing and failover b... Closed

 Description   

To reproduce (with replica set configured with actual host names and not numeric IP addresses):

var server = MongoServer.Create("mongodb://127.0.0.1:10001,127.0.0.1:10002,127.0.0.1:10003/?safe=true");
var database = server.GetDatabase("test");
var collection = database.GetCollection("test");
 
for (int i = 0; i < 3; i++)
{
    try
    {
        Console.WriteLine("Count = {0}", collection.Count());
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
    }
}

Output is:

Unable to connect to the primary member of the replica set.
Count = 1
Count = 1



 Comments   
Comment by Craig Wilson [ 07/Aug/12 ]

So, 2 things.

1) This particular bug was caused by the hostnames on the connection string not match the hostnames that the replica sets were created with. In other words, 127.0.0.1 would be on the connection string, but the replica set called itself localhost. In 1.5, this can be fixed by making sure your connection string uses the same names as the replica set knows about. You can check this by connecting to a replica set member and running rs.status().

2) The network is inherently unreliable. I'm not surprised you are seeing "some" connections failures. "some" = a few. Do you have a stack trace and can you correlate entries in the mongodb logs with the errors?

Comment by David Burke [ 07/Aug/12 ]

Hi We are on version 1.5 of the driver so I want to understand the original problem a little more. Why does the first connection fail? We are experiencing this problem in production at the moment but the connection failures appear to be happening intermitantly... could it be that the driver is reusing the bad connection? I have seen suggestions that recycling the app pool will clear the problem. does this make sense?

Comment by Craig Wilson [ 12/Jul/12 ]

This bug was handled by the refactoring to support mongos loadbalancing and failover.

Comment by auto [ 12/Jul/12 ]

Author:

{u'date': u'2012-07-12T08:40:54-07:00', u'email': u'craiggwilson@gmail.com', u'name': u'Craig Wilson'}

Message: CSHARP-500, CSHARP-519: refactored ReplicaSetMongoServerProxy and ShardedMongoServerProxy to use a common base class.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/07f73d4f9f579fe4a49930335a82b5290f0092df

Comment by auto [ 12/Jul/12 ]

Author:

{u'date': u'2012-07-12T04:52:53-07:00', u'email': u'craiggwilson@gmail.com', u'name': u'Craig Wilson'}

Message: CSHARP-500: more updates and refinements based on feedback.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/9b4e40ed813feb5b5f9e9f37214e843046b52fdf

Comment by auto [ 12/Jul/12 ]

Author:

{u'date': u'2012-07-11T21:11:28-07:00', u'email': u'robert@10gen.com', u'name': u'rstam'}

Message: CSHARP-500: minor refactoring and fixed some unit tests.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/d21dfa7826b6a4427c91e0d55cadc6d3b6bc557f

Comment by auto [ 12/Jul/12 ]

Author:

{u'date': u'2012-07-11T13:43:01-07:00', u'email': u'craiggwilson@gmail.com', u'name': u'Craig Wilson'}

Message: CSHARP-500:refactored connection logic. CSHARP-519: implemented mongos failover and load balancing.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/35432a8dc173348a1f7904644cf1f2f6ec706851

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