Skip to content

Commit a57bf47

Browse files
committed
Merge pull request AsyncHttpClient#1150 from charliechang/fix-retry-count-incremented-twice
Fix retry double increment in NettyConnectListener
2 parents 9d4599d + e83e96c commit a57bf47

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ public boolean reuseChannel() {
425425
return reuseChannel;
426426
}
427427

428-
public boolean canRetry() {
428+
public boolean incRetryAndCheck() {
429429
return maxRetry > 0 && CURRENT_RETRY_UPDATER.incrementAndGet(this) <= maxRetry;
430430
}
431431

@@ -444,7 +444,7 @@ public void setCurrentRequest(Request currentRequest) {
444444
* @return true if that {@link Future} cannot be recovered.
445445
*/
446446
public boolean canBeReplayed() {
447-
return !isDone() && canRetry() && !(Channels.isChannelValid(channel) && !getUri().getScheme().equalsIgnoreCase("https")) && !inAuth.get() && !inProxyAuth.get();
447+
return !isDone() && !(Channels.isChannelValid(channel) && !getUri().getScheme().equalsIgnoreCase("https")) && !inAuth.get() && !inProxyAuth.get();
448448
}
449449

450450
public long getStart() {

client/src/main/java/org/asynchttpclient/netty/channel/NettyConnectListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public void onFailure(Channel channel, Throwable cause) {
120120
//beware, channel can be null
121121
abortChannelPreemption();
122122

123-
boolean canRetry = future.canRetry();
123+
boolean canRetry = future.incRetryAndCheck();
124124
LOGGER.debug("Trying to recover from failing to connect channel {} with a retry value of {} ", channel, canRetry);
125125
if (canRetry//
126126
&& cause != null // FIXME when can we have a null cause?

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ public void abort(Channel channel, NettyResponseFuture<?> future, Throwable t) {
396396
public void handleUnexpectedClosedChannel(Channel channel, NettyResponseFuture<?> future) {
397397
if (future.isDone()) {
398398
channelManager.closeChannel(channel);
399-
} else if (retry(future)) {
399+
} else if (future.incRetryAndCheck() && retry(future)) {
400400
future.pendingException = null;
401401
} else {
402402
abort(channel, future, future.pendingException != null ? future.pendingException : RemotelyClosedException.INSTANCE);
@@ -447,7 +447,7 @@ public boolean applyIoExceptionFiltersAndReplayRequest(NettyResponseFuture<?> fu
447447
}
448448
}
449449

450-
if (fc.replayRequest() && future.canBeReplayed()) {
450+
if (fc.replayRequest() && future.canBeReplayed() && future.incRetryAndCheck()) {
451451
replayRequest(future, fc, channel);
452452
replayed = true;
453453
}

0 commit comments

Comments
 (0)