Skip to content

Commit 615f216

Browse files
author
Stephane Landelle
committed
NPE when Future.cancel happens before channel is attached, close AsyncHttpClient#762
1 parent 1a89a8e commit 615f216

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/main/java/com/ning/http/client/providers/netty/future/NettyResponseFuture.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,11 @@ public boolean cancel(boolean force) {
129129
if (isCancelled.getAndSet(true))
130130
return false;
131131

132-
Channels.setDiscard(channel);
133-
Channels.silentlyCloseChannel(channel);
132+
// cancel could happen before channel was attached
133+
if (channel != null) {
134+
Channels.setDiscard(channel);
135+
Channels.silentlyCloseChannel(channel);
136+
}
134137

135138
if (!onThrowableCalled.getAndSet(true)) {
136139
try {
@@ -371,6 +374,12 @@ public void setConnectAllowed(boolean allowConnect) {
371374
}
372375

373376
public void attachChannel(Channel channel, boolean reuseChannel) {
377+
378+
// future could have been cancelled first
379+
if (isDone()) {
380+
Channels.silentlyCloseChannel(channel);
381+
}
382+
374383
this.channel = channel;
375384
this.reuseChannel = reuseChannel;
376385
}

0 commit comments

Comments
 (0)