Skip to content

Commit 95b83dc

Browse files
committed
CSHARP-671: server sometimes neglects to return setName causing the driver to think that the instance is not a replica set member and we remove it from memory preventing recovery.
1 parent a441495 commit 95b83dc

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

MongoDB.Driver/CommandResults/IsMasterResult.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,17 @@ public bool IsPassive
7676
get { return Response.GetValue("passive", false).ToBoolean() && !IsArbiterOnly; }
7777
}
7878

79+
/// <summary>
80+
/// Gets a value indicating whether this instance is replica set.
81+
/// </summary>
82+
/// <value>
83+
/// <c>true</c> if this instance is replica set; otherwise, <c>false</c>.
84+
/// </value>
85+
public bool IsReplicaSet
86+
{
87+
get { return ReplicaSetName != null || Response.GetValue("isreplicaset", false).ToBoolean(); }
88+
}
89+
7990
/// <summary>
8091
/// Gets whether the server is secondary.
8192
/// </summary>

MongoDB.Driver/Communication/MongoServerInstance.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ private void LookupServerInformation(MongoConnection connection)
562562

563563
ReplicaSetInformation replicaSetInformation = null;
564564
MongoServerInstanceType instanceType = MongoServerInstanceType.StandAlone;
565-
if (isMasterResult.ReplicaSetName != null)
565+
if (isMasterResult.IsReplicaSet)
566566
{
567567
var peers = isMasterResult.Hosts.Concat(isMasterResult.Passives).Concat(isMasterResult.Arbiters).ToList();
568568
replicaSetInformation = new ReplicaSetInformation(isMasterResult.ReplicaSetName, isMasterResult.Primary, peers, isMasterResult.Tags);

MongoDB.Driver/Communication/Proxies/ReplicaSetMongoServerProxy.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,9 @@ protected override bool IsValidInstance(MongoServerInstance instance)
179179
// read _replicaSetName in a thread-safe way
180180
var replicaSetName = Interlocked.CompareExchange(ref _replicaSetName, null, null);
181181

182-
return replicaSetName == null || replicaSetName == instance.ReplicaSetInformation.Name;
182+
return replicaSetName == null ||
183+
instance.ReplicaSetInformation.Name == null ||
184+
replicaSetName == instance.ReplicaSetInformation.Name;
183185
}
184186

185187
/// <summary>

MongoDB.Driver/Communication/ReplicaSetInformation.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ internal sealed class ReplicaSetInformation : IEquatable<ReplicaSetInformation>
3939
/// <param name="tagSet">The tag set.</param>
4040
public ReplicaSetInformation(string name, MongoServerAddress primary, IEnumerable<MongoServerAddress> members, ReplicaSetTagSet tagSet)
4141
{
42-
if (name == null)
43-
{
44-
throw new ArgumentNullException("name");
45-
}
46-
4742
_name = name;
4843
_primary = primary;
4944
_members = members == null ? new List<MongoServerAddress>() : members.ToList();

0 commit comments

Comments
 (0)