Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit 7542d7baa9f529a4dcf6bb7a0be162c8e6949607 1 parent 90fa91c
Eric Milkie authored July 27, 2012

Showing 1 changed file with 13 additions and 1 deletion. Show diff stats Hide diff stats

  1. 14  client/dbclient_rs.cpp
14  client/dbclient_rs.cpp
@@ -225,6 +225,7 @@ namespace mongo {
225 225
     HostAndPort ReplicaSetMonitor::getMaster() {
226 226
         {
227 227
             scoped_lock lk( _lock );
  228
+            assert(_master < static_cast<int>(_nodes.size()));
228 229
             if ( _master >= 0 && _nodes[_master].ok )
229 230
                 return _nodes[_master].addr;
230 231
         }
@@ -233,6 +234,7 @@ namespace mongo {
233 234
 
234 235
         scoped_lock lk( _lock );
235 236
         uassert( 10009 , str::stream() << "ReplicaSetMonitor no master found for set: " << _name , _master >= 0 );
  237
+        assert(_master < static_cast<int>(_nodes.size()));
236 238
         return _nodes[_master].addr;
237 239
     }
238 240
     
@@ -467,6 +469,10 @@ namespace mongo {
467 469
 
468 470
             _nodes.push_back( Node( h , newConn ) );
469 471
         }
  472
+
  473
+        // Invalidate the cached _master index since the _nodes structure has
  474
+        // already been modified.
  475
+        _master = -1;
470 476
     }
471 477
     
472 478
 
@@ -552,7 +558,11 @@ namespace mongo {
552 558
 
553 559
         if ( errorOccured && nodesOffset >= 0 ) {
554 560
             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
+            }
556 566
         }
557 567
 
558 568
         if ( changed && _hook )
@@ -572,6 +582,7 @@ namespace mongo {
572 582
 
573 583
             if ( !checkAllSecondaries ) {
574 584
                 scoped_lock lk( _lock );
  585
+                assert(_master < static_cast<int>(_nodes.size()));
575 586
                 if ( _master >= 0 ) {
576 587
                   /* Nothing else to do since another thread already
577 588
                    * found the _master
@@ -662,6 +673,7 @@ namespace mongo {
662 673
 
663 674
             // first see if the current master is fine
664 675
             if ( _master >= 0 ) {
  676
+                assert(_master < static_cast<int>(_nodes.size()));
665 677
                 masterConn = _nodes[_master].conn;
666 678
             }
667 679
         }

0 notes on commit 7542d7b

Please sign in to comment.
Something went wrong with that request. Please try again.