Apache HTTP 客户端 org.apache.http.NoHttpResponseException 即使在较低的 validateAfterInactivity 之后

Apache HTTP client org.apache.http.NoHttpResponseException even after lower validateAfterInactivity

我有 HTTP 客户端,它偶尔会收到以下错误。在发生此异常时收到实际请求未命中目标服务器。

org.springframework.ws.client.WebServiceIOException: I/O error: xxxx:yy failed to respond; nested exception is org.apache.http.NoHttpResponseException: xxxx:yy failed to respond

Apache http 客户端版本:4.5.13

我已将 validateAfterInactivity 减少到 100 毫秒,但没有成功。我仍然以同样的速度收到错误。

我的 HttpClient 池配置如下。

    public PoolingHttpClientConnectionManager poolingHttpClientConnectionManager() {
        PoolingHttpClientConnectionManager result = new PoolingHttpClientConnectionManager();
        result.setMaxTotal(500);
        result.setDefaultMaxPerRoute(75);
        result.setValidateAfterInactivity(100);
        return result;
    }

这可以通过添加 HttpRequestRetryHandler 和 setValidateAfterInactivity 来解决。

httpClientBuilder.setRetryHandler(new HttpRequestRetryHandler() {
               @Override
               public boolean retryRequest(java.io.IOException exception, int executionCount, HttpContext context) {
                   if (executionCount > 2) {
                       log.warn("Skipped retry");
                       return false;
                   }
                   if (exception instanceof org.apache.http.NoHttpResponseException) {
                       log.warn("Executed retry " + exception.getMessage());
                       return true;
                   }
                   return false;
               }
           });