Skip to content

Commit 75d8cda

Browse files
committed
Check for premature end of stream in Async
JAVA-1881
1 parent 7eec8b2 commit 75d8cda

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

driver-core/src/main/com/mongodb/connection/AsynchronousSocketChannelStream.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.mongodb.connection;
1818

1919
import com.mongodb.MongoSocketOpenException;
20+
import com.mongodb.MongoSocketReadException;
2021
import com.mongodb.MongoSocketReadTimeoutException;
2122
import com.mongodb.ServerAddress;
2223
import org.bson.ByteBuf;
@@ -212,7 +213,10 @@ private BasicCompletionHandler(final ByteBuf dst, final AsyncCompletionHandler<B
212213

213214
@Override
214215
public void completed(final Integer result, final Void attachment) {
215-
if (!dst.hasRemaining()) {
216+
if (result == -1) {
217+
dst.release();
218+
handler.failed(new MongoSocketReadException("Prematurely reached end of stream", serverAddress));
219+
} else if (!dst.hasRemaining()) {
216220
dst.flip();
217221
handler.completed(dst);
218222
} else {

0 commit comments

Comments
 (0)