Skip to content

Commit 976253a

Browse files
committed
Fix NPE when channel is closed after being fetched from pool, close AsyncHttpClient#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
1 parent 385e86c commit 976253a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

client/src/main/java/org/asynchttpclient/netty/request/NettyRequestSender.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
import java.io.IOException;
4040
import java.net.InetSocketAddress;
41+
import java.net.SocketAddress;
4142
import java.util.List;
4243

4344
import org.asynchttpclient.AsyncHandler;
@@ -234,7 +235,12 @@ private <T> ListenableFuture<T> sendRequestWithOpenChannel(Request request, Prox
234235
}
235236
}
236237

237-
scheduleRequestTimeout(future, (InetSocketAddress) channel.remoteAddress());
238+
SocketAddress channelRemoteAddress = channel.remoteAddress();
239+
if (channelRemoteAddress != null) {
240+
// otherwise, bad luck, the channel was closed, see bellow
241+
scheduleRequestTimeout(future, (InetSocketAddress) channelRemoteAddress);
242+
}
243+
238244
future.setChannelState(ChannelState.POOLED);
239245
future.attachChannel(channel, false);
240246

0 commit comments

Comments
 (0)