Skip to content

Commit 978dfae

Browse files
committed
Handle cancelled SelectionKey in interestOps access
1 parent 127a32f commit 978dfae

2 files changed

Lines changed: 8 additions & 12 deletions

File tree

httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/CancellableExecution.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
*/
2727
package org.apache.hc.core5.http2.impl.nio.bootstrap;
2828

29-
import java.nio.channels.CancelledKeyException;
3029
import java.util.concurrent.atomic.AtomicBoolean;
3130
import java.util.concurrent.atomic.AtomicReference;
3231

@@ -49,11 +48,7 @@ public void setDependency(final Cancellable cancellable) {
4948
if (cancelled.get()) {
5049
final Cancellable dependency = dependencyRef.getAndSet(null);
5150
if (dependency != null) {
52-
try {
53-
dependency.cancel();
54-
} catch (final CancelledKeyException ignore) {
55-
// Session already gone; cancellation is effectively complete.
56-
}
51+
dependency.cancel();
5752
}
5853
}
5954
}
@@ -68,11 +63,7 @@ public boolean cancel() {
6863
if (cancelled.compareAndSet(false, true)) {
6964
final Cancellable dependency = dependencyRef.getAndSet(null);
7065
if (dependency != null) {
71-
try {
72-
dependency.cancel();
73-
} catch (final CancelledKeyException ignore) {
74-
// Session already gone; treat as successfully cancelled.
75-
}
66+
dependency.cancel();
7667
}
7768
return true;
7869
}

httpcore5/src/main/java/org/apache/hc/core5/reactor/IOSessionImpl.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.net.StandardSocketOptions;
3333
import java.nio.ByteBuffer;
3434
import java.nio.channels.ByteChannel;
35+
import java.nio.channels.CancelledKeyException;
3536
import java.nio.channels.SelectionKey;
3637
import java.nio.channels.SocketChannel;
3738
import java.util.Deque;
@@ -158,7 +159,11 @@ public SocketAddress getRemoteAddress() {
158159

159160
@Override
160161
public int getEventMask() {
161-
return this.key.interestOps();
162+
try {
163+
return this.key.interestOps();
164+
} catch (final CancelledKeyException ignore) {
165+
return 0;
166+
}
162167
}
163168

164169
@Override

0 commit comments

Comments
 (0)