Skip to content

Commit 47ab401

Browse files
committed
NettyStream fix
Ensure any cleanly closed connections from the server notify any pending readers that the connection has closed. JAVA-2306
1 parent 8799770 commit 47ab401

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

driver-core/src/main/com/mongodb/connection/netty/NettyStream.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.mongodb.MongoException;
2020
import com.mongodb.MongoInternalException;
2121
import com.mongodb.MongoInterruptedException;
22+
import com.mongodb.MongoSocketException;
2223
import com.mongodb.MongoSocketOpenException;
2324
import com.mongodb.MongoSocketReadTimeoutException;
2425
import com.mongodb.ServerAddress;
@@ -145,6 +146,12 @@ public void initChannel(final SocketChannel ch) throws Exception {
145146
public void operationComplete(final ChannelFuture future) throws Exception {
146147
if (future.isSuccess()) {
147148
channel = channelFuture.channel();
149+
channel.closeFuture().addListener(new ChannelFutureListener() {
150+
@Override
151+
public void operationComplete(final ChannelFuture f2) throws Exception {
152+
handleReadResponse(null, new IOException("The connection to the server was closed"));
153+
}
154+
});
148155
handler.completed(null);
149156
} else {
150157
handler.failed(new MongoSocketOpenException("Exception opening socket", getAddress(), future.cause()));

0 commit comments

Comments
 (0)