@@ -72,6 +72,7 @@ public sealed class MongoServerInstance
7272 private bool _inStateVerification ;
7373 private ServerInformation _serverInfo ;
7474 private IPEndPoint _ipEndPoint ;
75+ private bool _permanentlyDisconnected ;
7576 private int _sequentialId ;
7677 private MongoServerState _state ;
7778 private Timer _stateVerificationTimer ;
@@ -96,6 +97,7 @@ internal MongoServerInstance(MongoServer server, MongoServerAddress address)
9697 } ;
9798 _connectionPool = new MongoConnectionPool ( this ) ;
9899 _pingTimeAggregator = new PingTimeAggregator ( 5 ) ;
100+ _permanentlyDisconnected = false ;
99101 // Console.WriteLine("MongoServerInstance[{0}]: {1}", sequentialId, address);
100102 }
101103
@@ -425,7 +427,7 @@ internal void Connect()
425427 // Console.WriteLine("MongoServerInstance[{0}]: Connect() called.", sequentialId);
426428 lock ( _serverInstanceLock )
427429 {
428- if ( _state == MongoServerState . Connecting || _state == MongoServerState . Connected )
430+ if ( _permanentlyDisconnected || _state == MongoServerState . Connecting || _state == MongoServerState . Connected )
429431 {
430432 return ;
431433 }
@@ -513,6 +515,19 @@ internal void Disconnect()
513515 }
514516 }
515517
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+
516531 /// <summary>
517532 /// Releases the connection.
518533 /// </summary>
@@ -618,18 +633,20 @@ private void LookupServerInformation(MongoConnection connection)
618633 currentServerInfo = _serverInfo ;
619634 }
620635
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.
621638 var newServerInfo = new ServerInformation
622639 {
623- BuildInfo = null ,
640+ BuildInfo = currentServerInfo . BuildInfo ,
624641 InstanceType = currentServerInfo . InstanceType ,
625642 IsArbiter = false ,
626643 IsMasterResult = isMasterResult ,
627644 IsPassive = false ,
628645 IsPrimary = false ,
629646 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
633650 } ;
634651
635652 SetState ( MongoServerState . Disconnected , newServerInfo ) ;
0 commit comments