Skip to content

Commit d05bc12

Browse files
committed
JAVA-626: Fixing race condition in DBApiLayer.requestEnsureConnection
1 parent 5dbfb40 commit d05bc12

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/main/com/mongodb/DBTCPConnector.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ public void requestDone(){
126126
*/
127127
@Override
128128
public void requestEnsureConnection(){
129+
checkMaster( false , true );
129130
_myPort.get().requestEnsureConnection();
130131
}
131132

src/test/com/mongodb/DBTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.testng.annotations.Test;
2020

2121
import java.net.UnknownHostException;
22+
import java.util.Arrays;
2223

2324
public class DBTest extends TestCase {
2425

@@ -119,6 +120,27 @@ public void testReadPreferenceObedience() {
119120
assertEquals(ReadPreference.primary(), _db.getCommandReadPreference(obj, ReadPreference.secondary()));
120121
}
121122

123+
@Test(groups = {"basic"})
124+
public void testEnsureConnection() throws UnknownHostException {
125+
126+
Mongo m = new Mongo(Arrays.asList(new ServerAddress("localhost")));
127+
128+
if (isStandalone(m)) {
129+
return;
130+
}
131+
try {
132+
DB db = m.getDB("com_mongodb_unittest_DBTest");
133+
db.requestStart();
134+
try {
135+
db.requestEnsureConnection();
136+
} finally {
137+
db.requestDone();
138+
}
139+
} finally {
140+
m.close();
141+
}
142+
}
143+
122144
/*public static class Person extends DBObject {
123145
124146
public Person(){

0 commit comments

Comments
 (0)