Skip to content

Commit fecb116

Browse files
committed
Fix race condition causing NPE, close AsyncHttpClient#1049
1 parent 2e81bcc commit fecb116

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import static org.asynchttpclient.util.MiscUtils.getCause;
1818
import io.netty.channel.Channel;
1919

20-
import java.net.SocketAddress;
2120
import java.util.concurrent.CancellationException;
2221
import java.util.concurrent.CompletableFuture;
2322
import java.util.concurrent.CountDownLatch;
@@ -410,10 +409,6 @@ public boolean canRetry() {
410409
return maxRetry > 0 && currentRetry.incrementAndGet() <= maxRetry;
411410
}
412411

413-
public SocketAddress getChannelRemoteAddress() {
414-
return channel != null ? channel.remoteAddress() : null;
415-
}
416-
417412
public void setTargetRequest(Request targetRequest) {
418413
this.targetRequest = targetRequest;
419414
}

client/src/main/java/org/asynchttpclient/netty/timeout/TimeoutTimerTask.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*/
1414
package org.asynchttpclient.netty.timeout;
1515

16+
import io.netty.channel.Channel;
1617
import io.netty.util.TimerTask;
1718

1819
import java.net.SocketAddress;
@@ -39,8 +40,9 @@ public TimeoutTimerTask(NettyResponseFuture<?> nettyResponseFuture, NettyRequest
3940
this.requestSender = requestSender;
4041
this.timeoutsHolder = timeoutsHolder;
4142
// saving remote address as the channel might be removed from the future when an exception occurs
42-
SocketAddress sa = nettyResponseFuture.getChannelRemoteAddress();
43-
remoteAddress = sa != null ? sa.toString() : "not-connected";
43+
Channel channel = nettyResponseFuture.channel();
44+
SocketAddress sa = channel == null ? null : channel.remoteAddress();
45+
remoteAddress = sa == null ? "not-connected" : sa.toString();
4446
}
4547

4648
protected void expire(String message, long time) {

0 commit comments

Comments
 (0)