[#2104] Make sure we only act on the SelectionKey if it is valid

This commit is contained in:
Norman Maurer 2014-01-09 18:27:56 +01:00
parent b5f49203de
commit 13d65d7ccf

View File

@ -57,6 +57,12 @@ public abstract class AbstractNioByteChannel extends AbstractNioChannel {
private void removeReadOp() { private void removeReadOp() {
SelectionKey key = selectionKey(); SelectionKey key = selectionKey();
// Check first if the key is still valid as it may be canceled as part of the deregistration
// from the EventLoop
// See https://github.com/netty/netty/issues/2104
if (!key.isValid()) {
return;
}
int interestOps = key.interestOps(); int interestOps = key.interestOps();
if ((interestOps & readInterestOp) != 0) { if ((interestOps & readInterestOp) != 0) {
// only remove readInterestOp if needed // only remove readInterestOp if needed
@ -289,6 +295,12 @@ public abstract class AbstractNioByteChannel extends AbstractNioChannel {
protected final void setOpWrite() { protected final void setOpWrite() {
final SelectionKey key = selectionKey(); final SelectionKey key = selectionKey();
// Check first if the key is still valid as it may be canceled as part of the deregistration
// from the EventLoop
// See https://github.com/netty/netty/issues/2104
if (!key.isValid()) {
return;
}
final int interestOps = key.interestOps(); final int interestOps = key.interestOps();
if ((interestOps & SelectionKey.OP_WRITE) == 0) { if ((interestOps & SelectionKey.OP_WRITE) == 0) {
key.interestOps(interestOps | SelectionKey.OP_WRITE); key.interestOps(interestOps | SelectionKey.OP_WRITE);
@ -297,6 +309,12 @@ public abstract class AbstractNioByteChannel extends AbstractNioChannel {
protected final void clearOpWrite() { protected final void clearOpWrite() {
final SelectionKey key = selectionKey(); final SelectionKey key = selectionKey();
// Check first if the key is still valid as it may be canceled as part of the deregistration
// from the EventLoop
// See https://github.com/netty/netty/issues/2104
if (!key.isValid()) {
return;
}
final int interestOps = key.interestOps(); final int interestOps = key.interestOps();
if ((interestOps & SelectionKey.OP_WRITE) != 0) { if ((interestOps & SelectionKey.OP_WRITE) != 0) {
key.interestOps(interestOps & ~SelectionKey.OP_WRITE); key.interestOps(interestOps & ~SelectionKey.OP_WRITE);