Skip to content

Commit 12f4b2a

Browse files
authored
Cancel replaced timeouts to avoid leak (AsyncHttpClient#1732)
Fix for issue AsyncHttpClient#1731. When setting the TimeoutHolder, cancel any prior timeout so that they don't leak. Previously, they would just be lost and remain in the timer until their timeout expired, which could be a long time. Previously, encountering a redirect would trigger this code, causing the old request timer to be replaced with a new one. The old timer would maintain a link back to this Future, but couldn't be canceled by this future (as its reference had been overwritten) causing the Future, is associated Response, and any AsyncResponseHandler to be retained in memory instead of being garbage collected once the request had been processed.
1 parent b9b8836 commit 12f4b2a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Diff for: client/src/main/java/org/asynchttpclient/netty/NettyResponseFuture.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,10 @@ public TimeoutsHolder getTimeoutsHolder() {
366366
}
367367

368368
public void setTimeoutsHolder(TimeoutsHolder timeoutsHolder) {
369-
TIMEOUTS_HOLDER_FIELD.set(this, timeoutsHolder);
369+
TimeoutsHolder ref = TIMEOUTS_HOLDER_FIELD.getAndSet(this, timeoutsHolder);
370+
if (ref != null) {
371+
ref.cancel();
372+
}
370373
}
371374

372375
public boolean isInAuth() {

0 commit comments

Comments
 (0)