[#2615] Correctly update SelectionKey after selector rebuild
Motivation: When a select rebuild was triggered the reference to the SelectionKey is not updated in AbstractNioChannel. This will cause a CancelledKeyException later. Modification: Correctly update SelectionKey reference after rebuild Result: Fix exception
This commit is contained in:
parent
ff5b15acbd
commit
ac348956e3
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user