Skip to content

Commit cec8290

Browse files
author
Stephane Landelle
committed
minor clean up
1 parent 41e4c47 commit cec8290

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

providers/netty/src/main/java/org/asynchttpclient/providers/netty/request/timeout/ReadTimeoutTimerTask.java

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,36 +37,31 @@ public ReadTimeoutTimerTask(//
3737

3838
@Override
3939
public void run(Timeout timeout) throws Exception {
40-
if (requestSender.isClosed()) {
40+
41+
if (requestSender.isClosed() || nettyResponseFuture.isDone()) {
4142
timeoutsHolder.cancel();
4243
return;
4344
}
4445

45-
if (!nettyResponseFuture.isDone() && !nettyResponseFuture.isCancelled()) {
46-
47-
long now = millisTime();
46+
long now = millisTime();
4847

49-
long currentReadTimeoutInstant = readTimeout + nettyResponseFuture.getLastTouch();
50-
long durationBeforeCurrentReadTimeout = currentReadTimeoutInstant - now;
48+
long currentReadTimeoutInstant = readTimeout + nettyResponseFuture.getLastTouch();
49+
long durationBeforeCurrentReadTimeout = currentReadTimeoutInstant - now;
5150

52-
if (durationBeforeCurrentReadTimeout <= 0L) {
53-
// idleConnectionTimeout reached
54-
String message = "Idle connection timeout to " + nettyResponseFuture.getChannelRemoteAddress() + " of " + readTimeout + " ms";
55-
long durationSinceLastTouch = now - nettyResponseFuture.getLastTouch();
56-
expire(message, durationSinceLastTouch);
57-
nettyResponseFuture.setIdleConnectionTimeoutReached();
51+
if (durationBeforeCurrentReadTimeout <= 0L) {
52+
// idleConnectionTimeout reached
53+
String message = "Idle connection timeout to " + nettyResponseFuture.getChannelRemoteAddress() + " of " + readTimeout + " ms";
54+
long durationSinceLastTouch = now - nettyResponseFuture.getLastTouch();
55+
expire(message, durationSinceLastTouch);
56+
nettyResponseFuture.setIdleConnectionTimeoutReached();
5857

59-
} else if (currentReadTimeoutInstant < requestTimeoutInstant) {
60-
// reschedule
61-
timeoutsHolder.readTimeout = requestSender.newTimeout(this, durationBeforeCurrentReadTimeout);
62-
63-
} else {
64-
// otherwise, no need to reschedule: requestTimeout will happen sooner
65-
timeoutsHolder.readTimeout = null;
66-
}
58+
} else if (currentReadTimeoutInstant < requestTimeoutInstant) {
59+
// reschedule
60+
timeoutsHolder.readTimeout = requestSender.newTimeout(this, durationBeforeCurrentReadTimeout);
6761

6862
} else {
69-
timeoutsHolder.cancel();
63+
// otherwise, no need to reschedule: requestTimeout will happen sooner
64+
timeoutsHolder.readTimeout = null;
7065
}
7166
}
7267
}

0 commit comments

Comments
 (0)