Skip to content

Commit 6037357

Browse files
committed
JAVA-362: IllegalArgumentException due to race condition in updated thread start
1 parent cdb25d8 commit 6037357

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

src/main/com/mongodb/DBTCPConnector.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ public DBTCPConnector( Mongo m , List<ServerAddress> all )
6565

6666
_createLogger.info( all + " -> " + getAddress() );
6767
}
68+
69+
public void start() {
70+
if (_rsStatus != null)
71+
_rsStatus.start();
72+
}
6873

6974
private static ServerAddress _checkAddress( ServerAddress addr ){
7075
if ( addr == null )

src/main/com/mongodb/Mongo.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ public Mongo( ServerAddress addr , MongoOptions options )
190190
_options = options;
191191
_applyMongoOptions();
192192
_connector = new DBTCPConnector( this , _addr );
193+
_connector.start();
193194
_cleaner = new DBCleanerThread();
194195
_cleaner.start();
195196
}
@@ -227,6 +228,7 @@ public Mongo( ServerAddress left , ServerAddress right , MongoOptions options )
227228
_options = options;
228229
_applyMongoOptions();
229230
_connector = new DBTCPConnector( this , _addrs );
231+
_connector.start();
230232

231233
_cleaner = new DBCleanerThread();
232234
_cleaner.start();
@@ -301,6 +303,7 @@ public Mongo( MongoURI uri )
301303
_connector = new DBTCPConnector( this , replicaSetSeeds );
302304
}
303305

306+
_connector.start();
304307
_cleaner = new DBCleanerThread();
305308
_cleaner.start();
306309
}

src/main/com/mongodb/ReplicaSetStatus.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,12 @@ public class ReplicaSetStatus {
3838
_nextResolveTime = System.currentTimeMillis() + inetAddrCacheMS;
3939

4040
_updater = new Updater();
41-
_updater.start();
4241
}
4342

43+
void start() {
44+
_updater.start();
45+
}
46+
4447
boolean ready(){
4548
return _setName != null;
4649
}
@@ -435,6 +438,7 @@ public static void main( String args[] )
435438
Mongo m = new Mongo( addrs );
436439

437440
ReplicaSetStatus status = new ReplicaSetStatus( m, addrs );
441+
status.start();
438442
System.out.println( status.ensureMaster()._addr );
439443

440444
while ( true ){

0 commit comments

Comments
 (0)