Skip to content

Commit

Permalink
Fix NPE when channel is closed after being fetched from pool, close #…
Browse files Browse the repository at this point in the history
…1402

Motivation:

channel.remoteAddress() returns null if channel was closed after it was
pulled from the pool, causing a NPE.

Modification:

Only schedule timeout when channel’s remoteAddress is not null

Result:

No more NPE
  • Loading branch information
slandelle committed Apr 25, 2017
1 parent 385e86c commit 976253a
Showing 1 changed file with 7 additions and 1 deletion.
Expand Up @@ -38,6 +38,7 @@

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.List;

import org.asynchttpclient.AsyncHandler;
Expand Down Expand Up @@ -234,7 +235,12 @@ private <T> ListenableFuture<T> sendRequestWithOpenChannel(Request request, Prox
}
}

scheduleRequestTimeout(future, (InetSocketAddress) channel.remoteAddress());
SocketAddress channelRemoteAddress = channel.remoteAddress();
if (channelRemoteAddress != null) {
// otherwise, bad luck, the channel was closed, see bellow
scheduleRequestTimeout(future, (InetSocketAddress) channelRemoteAddress);
}

future.setChannelState(ChannelState.POOLED);
future.attachChannel(channel, false);

Expand Down

0 comments on commit 976253a

Please sign in to comment.