/// <summary> /// Verifies the state of the server instance. /// </summary> public void VerifyState() { lock (serverInstanceLock) { // Console.WriteLine("MongoServerInstance[{0}]: VerifyState called.", sequentialId); // if ping fails assume all connections in the connection pool are doomed try { Ping(); } catch { // Console.WriteLine("MongoServerInstance[{0}]: Ping failed: {1}.", sequentialId, ex.Message); connectionPool.Clear(); } var connection = connectionPool.AcquireConnection(null); try { var previousState = state; try { VerifyState(connection); } catch { // ignore exceptions (if any occured state will already be set to Disconnected) // Console.WriteLine("MongoServerInstance[{0}]: VerifyState failed: {1}.", sequentialId, ex.Message); } if (state != previousState && state == MongoServerState.Disconnected) { connectionPool.Clear(); } } finally { ReleaseConnection(connection); } } }
/// <summary> /// Verifies the state of the server instance. /// </summary> public void VerifyState() { lock (_serverInstanceLock) { // use a new connection instead of one from the connection pool var connection = new MongoConnection(this); try { // Console.WriteLine("MongoServerInstance[{0}]: VerifyState called.", sequentialId); // if ping fails assume all connections in the connection pool are doomed try { Ping(connection); } catch { // Console.WriteLine("MongoServerInstance[{0}]: Ping failed: {1}.", sequentialId, ex.Message); _connectionPool.Clear(); } var previousState = _state; try { VerifyState(connection); } catch { // ignore exceptions (if any occured state will already be set to Disconnected) // Console.WriteLine("MongoServerInstance[{0}]: VerifyState failed: {1}.", sequentialId, ex.Message); } if (_state != previousState && _state == MongoServerState.Disconnected) { _connectionPool.Clear(); } } finally { connection.Close(); } } }