[#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
cd62f2f21e
commit
8bf8252060
@ -46,7 +46,7 @@ public abstract class AbstractNioChannel extends AbstractChannel {
|
|||||||
|
|
||||||
private final SelectableChannel ch;
|
private final SelectableChannel ch;
|
||||||
protected final int readInterestOp;
|
protected final int readInterestOp;
|
||||||
private volatile SelectionKey selectionKey;
|
volatile SelectionKey selectionKey;
|
||||||
private volatile boolean inputShutdown;
|
private volatile boolean inputShutdown;
|
||||||
private volatile boolean readPending;
|
private volatile boolean readPending;
|
||||||
|
|
||||||
|
@ -259,7 +259,11 @@ public final class NioEventLoop extends SingleThreadEventLoop {
|
|||||||
|
|
||||||
int interestOps = key.interestOps();
|
int interestOps = key.interestOps();
|
||||||
key.cancel();
|
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 ++;
|
nChannels ++;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.warn("Failed to re-register a Channel to the new Selector.", e);
|
logger.warn("Failed to re-register a Channel to the new Selector.", e);
|
||||||
|
Loading…
Reference in New Issue
Block a user