You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2025/07/14 14:01:20 UTC

(httpcomponents-client) branch master updated: HTTPCLIENT-2371: Logging of request re-execution at INFO priority

This is an automated email from the ASF dual-hosted git repository.

olegk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git


The following commit(s) were added to refs/heads/master by this push:
     new 945a75dd3 HTTPCLIENT-2371: Logging of request re-execution at INFO priority
945a75dd3 is described below

commit 945a75dd361193620d4961ceeacbef77e69e8c76
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Sun Jul 13 10:35:57 2025 +0200

    HTTPCLIENT-2371: Logging of request re-execution at INFO priority
---
 .../http/impl/async/AsyncHttpRequestRetryExec.java | 25 ++++++++++++----------
 .../http/impl/classic/HttpRequestRetryExec.java    | 25 +++++++++++++---------
 2 files changed, 29 insertions(+), 21 deletions(-)

diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AsyncHttpRequestRetryExec.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AsyncHttpRequestRetryExec.java
index 90beadff7..325567cd6 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AsyncHttpRequestRetryExec.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AsyncHttpRequestRetryExec.java
@@ -29,7 +29,6 @@
 import java.io.IOException;
 
 import org.apache.hc.client5.http.HttpRequestRetryStrategy;
-import org.apache.hc.client5.http.HttpRoute;
 import org.apache.hc.client5.http.async.AsyncExecCallback;
 import org.apache.hc.client5.http.async.AsyncExecChain;
 import org.apache.hc.client5.http.async.AsyncExecChainHandler;
@@ -40,6 +39,7 @@
 import org.apache.hc.core5.annotation.ThreadingBehavior;
 import org.apache.hc.core5.http.EntityDetails;
 import org.apache.hc.core5.http.HttpException;
+import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.HttpRequest;
 import org.apache.hc.core5.http.HttpResponse;
 import org.apache.hc.core5.http.nio.AsyncDataConsumer;
@@ -96,6 +96,7 @@ public AsyncHttpRequestRetryExec(final HttpRequestRetryStrategy retryStrategy) {
     private static class State {
 
         volatile boolean retrying;
+        volatile int status;
         volatile TimeValue delay;
 
     }
@@ -125,6 +126,7 @@ public AsyncDataConsumer handleResponse(
                 }
                 state.retrying = retryStrategy.retryRequest(response, scope.execCount.get(), clientContext);
                 if (state.retrying) {
+                    state.status = response.getCode();
                     state.delay = retryStrategy.getRetryInterval(response, scope.execCount.get(), clientContext);
                     return new DiscardingEntityConsumer<>();
                 }
@@ -139,13 +141,16 @@ public void handleInformationResponse(final HttpResponse response) throws HttpEx
             @Override
             public void completed() {
                 if (state.retrying) {
-                    scope.execCount.incrementAndGet();
+                    final int execCount = scope.execCount.incrementAndGet();
                     if (entityProducer != null) {
                        entityProducer.releaseResources();
                     }
+                    final HttpHost target = scope.route.getTargetHost();
                     final TimeValue delay = TimeValue.isPositive(state.delay) ? state.delay : TimeValue.ZERO_MILLISECONDS;
-                    if (LOG.isDebugEnabled()) {
-                        LOG.debug("{} wait for {}", exchangeId, delay);
+                    if (LOG.isInfoEnabled()) {
+                        LOG.info("{} {} responded with status {}; " +
+                                        "request will be automatically re-executed in {} (exec count {})",
+                                exchangeId, target, state.status, delay, execCount);
                     }
                     scope.scheduler.scheduleExecution(
                             request,
@@ -162,7 +167,7 @@ public void completed() {
             @Override
             public void failed(final Exception cause) {
                 if (cause instanceof IOException) {
-                    final HttpRoute route = scope.route;
+                    final HttpHost target = scope.route.getTargetHost();
                     final HttpClientContext clientContext = scope.clientContext;
                     if (entityProducer != null && !entityProducer.isRepeatable()) {
                         if (LOG.isDebugEnabled()) {
@@ -172,10 +177,6 @@ public void failed(final Exception cause) {
                         if (LOG.isDebugEnabled()) {
                             LOG.debug("{} {}", exchangeId, cause.getMessage(), cause);
                         }
-                        if (LOG.isInfoEnabled()) {
-                            LOG.info("Recoverable I/O exception ({}) caught when processing request to {}",
-                                    cause.getClass().getName(), route);
-                        }
                         scope.execRuntime.discardEndpoint();
                         if (entityProducer != null) {
                             entityProducer.releaseResources();
@@ -184,8 +185,10 @@ public void failed(final Exception cause) {
                         final int execCount = scope.execCount.incrementAndGet();
                         state.delay = retryStrategy.getRetryInterval(request, (IOException) cause, execCount - 1, clientContext);
                         final TimeValue delay = TimeValue.isPositive(state.delay) ? state.delay : TimeValue.ZERO_MILLISECONDS;
-                        if (LOG.isDebugEnabled()) {
-                            LOG.debug("{} wait for {}", exchangeId, delay);
+                        if (LOG.isInfoEnabled()) {
+                            LOG.info("{} recoverable I/O exception ({}) caught when sending request to {};" +
+                                            "request will be automatically re-executed in {} (exec count {})",
+                                    exchangeId, cause.getClass().getName(), target, delay, execCount);
                         }
                         scope.scheduler.scheduleExecution(
                                 request,
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpRequestRetryExec.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpRequestRetryExec.java
index 2e0021085..3dc801dd3 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpRequestRetryExec.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpRequestRetryExec.java
@@ -43,6 +43,7 @@
 import org.apache.hc.core5.http.ClassicHttpResponse;
 import org.apache.hc.core5.http.HttpEntity;
 import org.apache.hc.core5.http.HttpException;
+import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.NoHttpResponseException;
 import org.apache.hc.core5.http.io.support.ClassicRequestBuilder;
 import org.apache.hc.core5.util.Args;
@@ -102,6 +103,7 @@ public ClassicHttpResponse execute(
         Args.notNull(scope, "scope");
         final String exchangeId = scope.exchangeId;
         final HttpRoute route = scope.route;
+        final HttpHost target = route.getTargetHost();
         final HttpClientContext context = scope.clientContext;
         ClassicHttpRequest currentRequest = request;
 
@@ -119,7 +121,12 @@ public ClassicHttpResponse execute(
                     if (retryStrategy.retryRequest(response, execCount, context)) {
                         response.close();
                         final TimeValue delay = retryStrategy.getRetryInterval(response, execCount, context);
-                        pause(exchangeId, delay);
+                        if (LOG.isInfoEnabled()) {
+                            LOG.info("{} {} responded with status {}; " +
+                                            "request will be automatically re-executed in {} (exec count {})",
+                                    exchangeId, target, response.getCode(), delay, execCount + 1);
+                        }
+                        pause(delay);
                         currentRequest = ClassicRequestBuilder.copy(scope.originalRequest).build();
                     } else {
                         return response;
@@ -143,18 +150,19 @@ public ClassicHttpResponse execute(
                     if (LOG.isDebugEnabled()) {
                         LOG.debug("{} {}", exchangeId, ex.getMessage(), ex);
                     }
+                    final TimeValue delay = retryStrategy.getRetryInterval(request, ex, execCount, context);
                     if (LOG.isInfoEnabled()) {
-                        LOG.info("Recoverable I/O exception ({}) caught when processing request to {}",
-                                ex.getClass().getName(), route);
+                        LOG.info("{} recoverable I/O exception ({}) caught when sending request to {};" +
+                                        "request will be automatically re-executed in {} (exec count {})",
+                                exchangeId, ex.getClass().getName(), target, delay, execCount + 1);
                     }
-                    final TimeValue delay = retryStrategy.getRetryInterval(request, ex, execCount, context);
-                    pause(exchangeId, delay);
+                    pause(delay);
                     currentRequest = ClassicRequestBuilder.copy(scope.originalRequest).build();
                     continue;
                 }
                 if (ex instanceof NoHttpResponseException) {
                     final NoHttpResponseException updatedex = new NoHttpResponseException(
-                            route.getTargetHost().toHostString() + " failed to respond");
+                            target.toHostString() + " failed to respond");
                     updatedex.setStackTrace(ex.getStackTrace());
                     throw updatedex;
                 }
@@ -163,10 +171,7 @@ public ClassicHttpResponse execute(
         }
     }
 
-    private static void pause(final String exchangeId, final TimeValue delay) throws InterruptedIOException {
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("{} wait for {}", exchangeId, delay);
-        }
+    private static void pause(final TimeValue delay) throws InterruptedIOException {
         if (TimeValue.isPositive(delay)) {
             try {
                 delay.sleep();