Permalink
Browse files

SERVER-6512 ReplicaSetMonitor::_checkConnection does not check upper …

…bounds for the indexes

Make sure to invalidate the cached _master index whenever the _nodes structure is modified.
This is a short term fix - the long term is to not use indexes at all.
  • Loading branch information...
1 parent 90fa91c commit 7542d7baa9f529a4dcf6bb7a0be162c8e6949607 @milkie milkie committed Jul 27, 2012
Showing with 13 additions and 1 deletion.
  1. +13 −1 client/dbclient_rs.cpp
View
@@ -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;
}
}

0 comments on commit 7542d7b

Please sign in to comment.