diff --git a/src/java.base/share/classes/sun/nio/ch/NioSocketImpl.java b/src/java.base/share/classes/sun/nio/ch/NioSocketImpl.java index b9885a36fa8..848b548bb3f 100644 --- a/src/java.base/share/classes/sun/nio/ch/NioSocketImpl.java +++ b/src/java.base/share/classes/sun/nio/ch/NioSocketImpl.java @@ -295,8 +295,10 @@ private int implRead(byte[] b, int off, int len) throws IOException { try { if (connectionReset) throw new SocketException("Connection reset"); - if (isInputClosed) + if (isInputClosed) { + System.err.println("input is closed, returning EOF"); return -1; + } int timeout = this.timeout; configureNonBlockingIfNeeded(fd, timeout > 0); if (timeout > 0) { @@ -310,6 +312,9 @@ private int implRead(byte[] b, int off, int len) throws IOException { n = tryRead(fd, b, off, len); } } + if (n == -1) { + System.err.println("Socket read() returning -1"); + } return n; } catch (InterruptedIOException e) { throw e; @@ -339,13 +344,17 @@ private int read(byte[] b, int off, int len) throws IOException { readLock.lock(); try { // emulate legacy behavior to return -1, even if socket is closed - if (readEOF) + if (readEOF) { + System.err.println("already reached EOF, returning -1"); return -1; + } // read up to MAX_BUFFER_SIZE bytes int size = Math.min(len, MAX_BUFFER_SIZE); int n = implRead(b, off, size); - if (n == -1) + if (n == -1) { + System.err.println("marking EOF"); readEOF = true; + } return n; } finally { readLock.unlock(); diff --git a/src/java.base/unix/native/libnio/ch/SocketDispatcher.c b/src/java.base/unix/native/libnio/ch/SocketDispatcher.c index bb987fc3b3d..546e82efcd4 100644 --- a/src/java.base/unix/native/libnio/ch/SocketDispatcher.c +++ b/src/java.base/unix/native/libnio/ch/SocketDispatcher.c @@ -45,7 +45,11 @@ JNU_ThrowByName(env, "sun/net/ConnectionResetException", "Connection reset"); return IOS_THROWN; } else { - return convertReturnVal(env, n, JNI_TRUE); + int read_ret = convertReturnVal(env, n, JNI_TRUE); + if (read_ret == -1) { + fprintf(stderr, "underlying read returned %d, returning EOF\n", n); + } + return read_ret; } }