Skip to content

Commit 7542d7b

Browse files
committed
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.
1 parent 90fa91c commit 7542d7b

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

client/dbclient_rs.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ namespace mongo {
225225
HostAndPort ReplicaSetMonitor::getMaster() {
226226
{
227227
scoped_lock lk( _lock );
228+
assert(_master < static_cast<int>(_nodes.size()));
228229
if ( _master >= 0 && _nodes[_master].ok )
229230
return _nodes[_master].addr;
230231
}
@@ -233,6 +234,7 @@ namespace mongo {
233234

234235
scoped_lock lk( _lock );
235236
uassert( 10009 , str::stream() << "ReplicaSetMonitor no master found for set: " << _name , _master >= 0 );
237+
assert(_master < static_cast<int>(_nodes.size()));
236238
return _nodes[_master].addr;
237239
}
238240

@@ -467,6 +469,10 @@ namespace mongo {
467469

468470
_nodes.push_back( Node( h , newConn ) );
469471
}
472+
473+
// Invalidate the cached _master index since the _nodes structure has
474+
// already been modified.
475+
_master = -1;
470476
}
471477

472478

@@ -552,7 +558,11 @@ namespace mongo {
552558

553559
if ( errorOccured && nodesOffset >= 0 ) {
554560
scoped_lock lk( _lock );
555-
_nodes[nodesOffset].ok = false;
561+
562+
if (_checkConnMatch_inlock(conn, nodesOffset)) {
563+
// Make sure _checkHosts didn't modify the _nodes structure
564+
_nodes[nodesOffset].ok = false;
565+
}
556566
}
557567

558568
if ( changed && _hook )
@@ -572,6 +582,7 @@ namespace mongo {
572582

573583
if ( !checkAllSecondaries ) {
574584
scoped_lock lk( _lock );
585+
assert(_master < static_cast<int>(_nodes.size()));
575586
if ( _master >= 0 ) {
576587
/* Nothing else to do since another thread already
577588
* found the _master
@@ -662,6 +673,7 @@ namespace mongo {
662673

663674
// first see if the current master is fine
664675
if ( _master >= 0 ) {
676+
assert(_master < static_cast<int>(_nodes.size()));
665677
masterConn = _nodes[_master].conn;
666678
}
667679
}

0 commit comments

Comments
 (0)