diff --git a/transport/src/main/java/io/netty/channel/nio/AbstractNioChannel.java b/transport/src/main/java/io/netty/channel/nio/AbstractNioChannel.java index c71467ce9e..516a94f665 100644 --- a/transport/src/main/java/io/netty/channel/nio/AbstractNioChannel.java +++ b/transport/src/main/java/io/netty/channel/nio/AbstractNioChannel.java @@ -46,7 +46,7 @@ public abstract class AbstractNioChannel extends AbstractChannel { private final SelectableChannel ch; protected final int readInterestOp; - private volatile SelectionKey selectionKey; + volatile SelectionKey selectionKey; private volatile boolean inputShutdown; private volatile boolean readPending; diff --git a/transport/src/main/java/io/netty/channel/nio/NioEventLoop.java b/transport/src/main/java/io/netty/channel/nio/NioEventLoop.java index ab853e9521..bd7673a953 100644 --- a/transport/src/main/java/io/netty/channel/nio/NioEventLoop.java +++ b/transport/src/main/java/io/netty/channel/nio/NioEventLoop.java @@ -259,7 +259,11 @@ public final class NioEventLoop extends SingleThreadEventLoop { int interestOps = key.interestOps(); key.cancel(); - key.channel().register(newSelector, interestOps, a); + SelectionKey newKey = key.channel().register(newSelector, interestOps, a); + if (a instanceof AbstractNioChannel) { + // Update SelectionKey + ((AbstractNioChannel) a).selectionKey = newKey; + } nChannels ++; } catch (Exception e) { logger.warn("Failed to re-register a Channel to the new Selector.", e);