Skip to content

Commit 7bf40d3

Browse files
committed
Make TimeoutsHolder.start idempotent
1 parent c1af3a4 commit 7bf40d3

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

‎client/src/main/java/org/asynchttpclient/netty/timeout/TimeoutsHolder.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public class TimeoutsHolder {
4343
private static final Logger LOGGER = LoggerFactory.getLogger(TimeoutsHolder.class);
4444

4545
private final AtomicBoolean cancelled = new AtomicBoolean();
46+
private final AtomicBoolean started = new AtomicBoolean();
4647
private final Timer nettyTimer;
4748
private volatile @Nullable EventExecutor eventExecutor;
4849
private final NettyRequestSender requestSender;
@@ -105,8 +106,14 @@ public TimeoutsHolder(Timer nettyTimer, @Nullable EventExecutor eventExecutor, N
105106
* <p>
106107
* Called by {@link org.asynchttpclient.netty.NettyResponseFuture#setTimeoutsHolder}, so that installing a
107108
* holder is what arms it and neither can be done without the other.
109+
* <p>
110+
* Only the first call arms. A second would overwrite the first handle, leaving an entry nobody can
111+
* cancel to sit in its scheduler until the full deadline, pinning the task, the future and the channel.
108112
*/
109113
public void start() {
114+
if (!started.compareAndSet(false, true)) {
115+
return;
116+
}
110117
if (requestTimeoutTask != null) {
111118
// The configured duration rather than the remaining time: this runs within microseconds of the
112119
// constructor, and reading the clock again would only expose the deadline to a step between the two.

0 commit comments

Comments
 (0)