Skip to content

Commit 56e9037

Browse files
committed
Improve the error handling in DBPort.ensureOpen when calling the buildInfo command
JAVA-1635
1 parent 6a58c6d commit 56e9037

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/main/com/mongodb/DBPort.java

+16-3
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,6 @@ private synchronized void ensureOpen(final Mongo mongo) throws IOException {
291291
_socket.setSoTimeout( _options.socketTimeout );
292292
_in = new BufferedInputStream( _socket.getInputStream() );
293293
_out = _socket.getOutputStream();
294-
if (mongo != null) {
295-
_serverVersion = getVersion(runCommand(mongo.getDB("admin"), new BasicDBObject("buildinfo", 1)));
296-
}
297294
successfullyConnected = true;
298295
}
299296
catch ( IOException e ){
@@ -316,6 +313,22 @@ private synchronized void ensureOpen(final Mongo mongo) throws IOException {
316313
sleepTime *= 2;
317314
}
318315
} while (!successfullyConnected);
316+
317+
if (mongo != null) {
318+
try {
319+
CommandResult buildInfoResult = runCommand(mongo.getDB("admin"), new BasicDBObject("buildinfo", 1));
320+
buildInfoResult.throwOnError();
321+
_serverVersion = getVersion(buildInfoResult);
322+
}
323+
catch (IOException e) {
324+
close();
325+
throw e;
326+
}
327+
catch (RuntimeException e) {
328+
close();
329+
throw e;
330+
}
331+
}
319332
}
320333

321334
@SuppressWarnings("unchecked")

0 commit comments

Comments
 (0)