Skip to content

Commit 3e95bb3

Browse files
committed
JAVA-1984: When retrying attempts to connect, close the socket and streams but not the DBPort itself
1 parent 11428b7 commit 3e95bb3

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/main/com/mongodb/DBPort.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ private synchronized void ensureOpen(final Mongo mongo) throws IOException {
293293
successfullyConnected = true;
294294
}
295295
catch ( IOException e ){
296-
close();
296+
reset();
297297

298298
if (!_options.autoConnectRetry || (provider != null && !provider.hasWorked()))
299299
throw e;
@@ -388,8 +388,12 @@ public boolean isClosed() {
388388
@Override
389389
public void close(){
390390
closed = true;
391+
reset();
392+
}
393+
394+
private void reset() {
391395
authenticatedDatabases.clear();
392-
396+
393397
if ( _socket != null ){
394398
try {
395399
_socket.close();
@@ -398,7 +402,7 @@ public void close(){
398402
// don't care
399403
}
400404
}
401-
405+
402406
_in = null;
403407
_out = null;
404408
_socket = null;

0 commit comments

Comments
 (0)