diff --git a/transport-native-epoll/src/main/java/io/netty/channel/epoll/AbstractEpollStreamChannel.java b/transport-native-epoll/src/main/java/io/netty/channel/epoll/AbstractEpollStreamChannel.java index 7fdb2a3b3c..ada3bc1df1 100644 --- a/transport-native-epoll/src/main/java/io/netty/channel/epoll/AbstractEpollStreamChannel.java +++ b/transport-native-epoll/src/main/java/io/netty/channel/epoll/AbstractEpollStreamChannel.java @@ -884,7 +884,6 @@ public abstract class AbstractEpollStreamChannel extends AbstractEpollChannel im if (close) { shutdownInput(); - close = false; } } catch (Throwable t) { handleReadException(pipeline, byteBuf, t, close, allocHandle); diff --git a/transport/src/main/java/io/netty/channel/nio/AbstractNioByteChannel.java b/transport/src/main/java/io/netty/channel/nio/AbstractNioByteChannel.java index 348ae2c677..1fae623c17 100644 --- a/transport/src/main/java/io/netty/channel/nio/AbstractNioByteChannel.java +++ b/transport/src/main/java/io/netty/channel/nio/AbstractNioByteChannel.java @@ -105,6 +105,7 @@ public abstract class AbstractNioByteChannel extends AbstractNioChannel { allocHandle.reset(config); ByteBuf byteBuf = null; + boolean close = false; try { boolean needReadPendingReset = true; do { @@ -114,6 +115,7 @@ public abstract class AbstractNioByteChannel extends AbstractNioChannel { // nothing was read. release the buffer. byteBuf.release(); byteBuf = null; + close = allocHandle.lastBytesRead() < 0; break; } @@ -129,11 +131,11 @@ public abstract class AbstractNioByteChannel extends AbstractNioChannel { allocHandle.readComplete(); pipeline.fireChannelReadComplete(); - if (allocHandle.lastBytesRead() < 0) { + if (close) { closeOnRead(pipeline); } } catch (Throwable t) { - handleReadException(pipeline, byteBuf, t, allocHandle.lastBytesRead() < 0, allocHandle); + handleReadException(pipeline, byteBuf, t, close, allocHandle); } finally { // Check if there is a readPending which was not processed yet. // This could be for two reasons: