[#2104] Make sure we only act on the SelectionKey if it is valid
This commit is contained in:
parent
ae1532ac50
commit
9276fbaea0
@ -58,6 +58,12 @@ public abstract class AbstractNioByteChannel extends AbstractNioChannel {
|
||||
|
||||
private void removeReadOp() {
|
||||
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();
|
||||
if ((interestOps & readInterestOp) != 0) {
|
||||
// only remove readInterestOp if needed
|
||||
@ -279,6 +285,12 @@ public abstract class AbstractNioByteChannel extends AbstractNioChannel {
|
||||
|
||||
protected final void setOpWrite() {
|
||||
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();
|
||||
if ((interestOps & SelectionKey.OP_WRITE) == 0) {
|
||||
key.interestOps(interestOps | SelectionKey.OP_WRITE);
|
||||
@ -287,6 +299,12 @@ public abstract class AbstractNioByteChannel extends AbstractNioChannel {
|
||||
|
||||
protected final void clearOpWrite() {
|
||||
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();
|
||||
if ((interestOps & SelectionKey.OP_WRITE) != 0) {
|
||||
key.interestOps(interestOps & ~SelectionKey.OP_WRITE);
|
||||
|
Loading…
Reference in New Issue
Block a user