@@ -72,6 +72,7 @@ public sealed class MongoServerInstance
72
72
private bool _inStateVerification ;
73
73
private ServerInformation _serverInfo ;
74
74
private IPEndPoint _ipEndPoint ;
75
+ private bool _permanentlyDisconnected ;
75
76
private int _sequentialId ;
76
77
private MongoServerState _state ;
77
78
private Timer _stateVerificationTimer ;
@@ -96,6 +97,7 @@ internal MongoServerInstance(MongoServer server, MongoServerAddress address)
96
97
} ;
97
98
_connectionPool = new MongoConnectionPool ( this ) ;
98
99
_pingTimeAggregator = new PingTimeAggregator ( 5 ) ;
100
+ _permanentlyDisconnected = false ;
99
101
// Console.WriteLine("MongoServerInstance[{0}]: {1}", sequentialId, address);
100
102
}
101
103
@@ -425,7 +427,7 @@ internal void Connect()
425
427
// Console.WriteLine("MongoServerInstance[{0}]: Connect() called.", sequentialId);
426
428
lock ( _serverInstanceLock )
427
429
{
428
- if ( _state == MongoServerState . Connecting || _state == MongoServerState . Connected )
430
+ if ( _permanentlyDisconnected || _state == MongoServerState . Connecting || _state == MongoServerState . Connected )
429
431
{
430
432
return ;
431
433
}
@@ -513,6 +515,19 @@ internal void Disconnect()
513
515
}
514
516
}
515
517
518
+ /// <summary>
519
+ /// Disconnects this instance permanently.
520
+ /// </summary>
521
+ internal void DisconnectPermanently ( )
522
+ {
523
+ lock ( _serverInstanceLock )
524
+ {
525
+ _permanentlyDisconnected = true ;
526
+ }
527
+
528
+ Disconnect ( ) ;
529
+ }
530
+
516
531
/// <summary>
517
532
/// Releases the connection.
518
533
/// </summary>
@@ -618,18 +633,20 @@ private void LookupServerInformation(MongoConnection connection)
618
633
currentServerInfo = _serverInfo ;
619
634
}
620
635
636
+ // keep the current instance type, build info, and replica set info
637
+ // as these aren't relevent to state and are likely still correct.
621
638
var newServerInfo = new ServerInformation
622
639
{
623
- BuildInfo = null ,
640
+ BuildInfo = currentServerInfo . BuildInfo ,
624
641
InstanceType = currentServerInfo . InstanceType ,
625
642
IsArbiter = false ,
626
643
IsMasterResult = isMasterResult ,
627
644
IsPassive = false ,
628
645
IsPrimary = false ,
629
646
IsSecondary = false ,
630
- MaxDocumentSize = MongoDefaults . MaxDocumentSize ,
631
- MaxMessageLength = MongoDefaults . MaxMessageLength ,
632
- ReplicaSetInformation = null
647
+ MaxDocumentSize = currentServerInfo . MaxDocumentSize ,
648
+ MaxMessageLength = currentServerInfo . MaxMessageLength ,
649
+ ReplicaSetInformation = currentServerInfo . ReplicaSetInformation
633
650
} ;
634
651
635
652
SetState ( MongoServerState . Disconnected , newServerInfo ) ;
0 commit comments