Skip to content

Commit 4bd4f10

Browse files
author
prat
committed
Fix NPE race in NettyResponseFuture.cancel (AsyncHttpClient#2042)
1 parent 14ee30a commit 4bd4f10

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

client/src/main/java/org/asynchttpclient/netty/NettyResponseFuture.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,10 @@ public boolean cancel(boolean force) {
187187
return false;
188188
}
189189

190-
// cancel could happen before channel was attached
191-
if (channel != null) {
192-
Channels.setDiscard(channel);
193-
Channels.silentlyCloseChannel(channel);
190+
Channel ch = channel; //atomic read, so that it won't end up in TOCTOU
191+
if (ch != null) {
192+
Channels.setDiscard(ch);
193+
Channels.silentlyCloseChannel(ch);
194194
}
195195

196196
if (ON_THROWABLE_CALLED_FIELD.getAndSet(this, 1) == 0) {

0 commit comments

Comments
 (0)