[CSHARP-1153] MongoServer.Ping() does not detect if servers go offline Created: 22/Dec/14  Updated: 22/Dec/14  Resolved: 22/Dec/14

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

Type: Bug Priority: Critical - P2
Reporter: Michael C Assignee: Unassigned
Resolution: Won't Fix Votes: 0
Labels: connection
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Official NuGet package, .NET 4.5 on Windows 7



 Description   

When using a connection string with multiple servers in a replicaset, Ping() does not detect if one of the MongoDB instances go offline, it will not throw an exception.
Only if I call Reconnect() will the driver detect that one of the instances are offline and throw an exception when calling Ping().

An easy way to test is to put one of the MongoDb instance hostnames in your hosts file and point it to 127.0.0.1, assuming you don't have mongodb running on your localhost.



 Comments   
Comment by Craig Wilson [ 22/Dec/14 ]

The best thing to do is do a db.RunCommand("replSetGetStatus") against the admin database. This will give you a complete overview of the replica set.

However, instead of calling ping, you can simply look at the Instances property of MongoServer (https://github.com/mongodb/mongo-csharp-driver/blob/v1.x/MongoDB.Driver/MongoServer.cs#L252) and loop over them. They are as up-to-date as the last health-check the driver made (about every 10 seconds).

Ping is not something we are planning on touching, so I'm going to close this as Won't Fix given that the above 2 solutions are better.

Comment by Michael C [ 22/Dec/14 ]

I'm trying to check whether all the servers in the replicaset are online, so I can generate a status page for the sysops guys.

Comment by Craig Wilson [ 22/Dec/14 ]

Hi Michael,

Perhaps you could indicate what you are trying to do and why and I could point you at a better solution than the Ping method.

Craig

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