diff options
-rw-r--r-- | client/dbclient_rs.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/client/dbclient_rs.cpp b/client/dbclient_rs.cpp index 6a4bf1dea63..be66bb451c4 100644 --- a/client/dbclient_rs.cpp +++ b/client/dbclient_rs.cpp @@ -225,6 +225,7 @@ namespace mongo { HostAndPort ReplicaSetMonitor::getMaster() { { scoped_lock lk( _lock ); + assert(_master < static_cast<int>(_nodes.size())); if ( _master >= 0 && _nodes[_master].ok ) return _nodes[_master].addr; } @@ -233,6 +234,7 @@ namespace mongo { scoped_lock lk( _lock ); uassert( 10009 , str::stream() << "ReplicaSetMonitor no master found for set: " << _name , _master >= 0 ); + assert(_master < static_cast<int>(_nodes.size())); return _nodes[_master].addr; } @@ -467,6 +469,10 @@ namespace mongo { _nodes.push_back( Node( h , newConn ) ); } + + // Invalidate the cached _master index since the _nodes structure has + // already been modified. + _master = -1; } @@ -552,7 +558,11 @@ namespace mongo { if ( errorOccured && nodesOffset >= 0 ) { scoped_lock lk( _lock ); - _nodes[nodesOffset].ok = false; + + if (_checkConnMatch_inlock(conn, nodesOffset)) { + // Make sure _checkHosts didn't modify the _nodes structure + _nodes[nodesOffset].ok = false; + } } if ( changed && _hook ) @@ -572,6 +582,7 @@ namespace mongo { if ( !checkAllSecondaries ) { scoped_lock lk( _lock ); + assert(_master < static_cast<int>(_nodes.size())); if ( _master >= 0 ) { /* Nothing else to do since another thread already * found the _master @@ -662,6 +673,7 @@ namespace mongo { // first see if the current master is fine if ( _master >= 0 ) { + assert(_master < static_cast<int>(_nodes.size())); masterConn = _nodes[_master].conn; } } |