File tree Expand file tree Collapse file tree 2 files changed +27
-4
lines changed Expand file tree Collapse file tree 2 files changed +27
-4
lines changed Original file line number Diff line number Diff line change @@ -1152,9 +1152,19 @@ public virtual void VerifyState()
1152
1152
{
1153
1153
lock ( _serverLock )
1154
1154
{
1155
- foreach ( var instance in _instances )
1155
+ var instances = Instances ; // create a copy that we can safely iterate over
1156
+ foreach ( var instance in instances )
1156
1157
{
1157
- instance . VerifyState ( ) ;
1158
+ bool isInstanceStillValid ;
1159
+ lock ( _stateLock )
1160
+ {
1161
+ isInstanceStillValid = _instances . Contains ( instance ) ;
1162
+ }
1163
+
1164
+ if ( isInstanceStillValid )
1165
+ {
1166
+ instance . VerifyState ( ) ;
1167
+ }
1158
1168
}
1159
1169
}
1160
1170
}
@@ -1421,9 +1431,16 @@ private void VerifyUnknownStates()
1421
1431
{
1422
1432
lock ( _serverLock )
1423
1433
{
1424
- foreach ( var instance in _instances )
1434
+ var instances = Instances ; // create a copy that we can safely iterate over
1435
+ foreach ( var instance in instances )
1425
1436
{
1426
- if ( instance . State == MongoServerState . Unknown )
1437
+ bool isInstanceStillValid ;
1438
+ lock ( _stateLock )
1439
+ {
1440
+ isInstanceStillValid = _instances . Contains ( instance ) ;
1441
+ }
1442
+
1443
+ if ( isInstanceStillValid && instance . State == MongoServerState . Unknown )
1427
1444
{
1428
1445
instance . VerifyState ( ) ;
1429
1446
}
Original file line number Diff line number Diff line change @@ -287,6 +287,12 @@ public void TestSecondaries()
287
287
Assert . AreEqual ( 0 , _server . Secondaries . Length ) ;
288
288
}
289
289
290
+ [ Test ]
291
+ public void TestVerifyState ( )
292
+ {
293
+ _server . VerifyState ( ) ;
294
+ }
295
+
290
296
[ Test ]
291
297
public void TestVersion ( )
292
298
{
You can’t perform that action at this time.
0 commit comments