[#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:
Norman Maurer 2014-06-27 17:09:27 +02:00
parent cd62f2f21e
commit 8bf8252060
2 changed files with 6 additions and 2 deletions

View File

@ -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;

View File

@ -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);