From 755b69ea3cc44557ed0517b7348ab16870a39975 Mon Sep 17 00:00:00 2001 From: Jaikiran Pai Date: Sun, 22 Aug 2021 19:17:57 +0530 Subject: [PATCH] Don't retry a request for NoRouteToHostException --- .../http/impl/DefaultHttpRequestRetryStrategy.java | 3 +++ .../http/impl/TestDefaultHttpRequestRetryStrategy.java | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultHttpRequestRetryStrategy.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultHttpRequestRetryStrategy.java index 2f8695af7..b1be581ca 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultHttpRequestRetryStrategy.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultHttpRequestRetryStrategy.java @@ -30,6 +30,7 @@ package org.apache.hc.client5.http.impl; import java.io.IOException; import java.io.InterruptedIOException; import java.net.ConnectException; +import java.net.NoRouteToHostException; import java.net.UnknownHostException; import java.util.Arrays; import java.util.Collection; @@ -106,6 +107,7 @@ public class DefaultHttpRequestRetryStrategy implements HttpRequestRetryStrategy *
  • UnknownHostException
  • *
  • ConnectException
  • *
  • ConnectionClosedException
  • + *
  • NoRouteToHostException
  • *
  • SSLException
  • * * @@ -129,6 +131,7 @@ public class DefaultHttpRequestRetryStrategy implements HttpRequestRetryStrategy UnknownHostException.class, ConnectException.class, ConnectionClosedException.class, + NoRouteToHostException.class, SSLException.class), Arrays.asList( HttpStatus.SC_TOO_MANY_REQUESTS, diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/TestDefaultHttpRequestRetryStrategy.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/TestDefaultHttpRequestRetryStrategy.java index 0411326e4..fc8c575dd 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/TestDefaultHttpRequestRetryStrategy.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/TestDefaultHttpRequestRetryStrategy.java @@ -28,6 +28,7 @@ package org.apache.hc.client5.http.impl; import java.io.IOException; import java.net.ConnectException; +import java.net.NoRouteToHostException; import java.net.SocketTimeoutException; import java.net.UnknownHostException; import java.util.Date; @@ -126,6 +127,13 @@ public class TestDefaultHttpRequestRetryStrategy { Assert.assertFalse(retryStrategy.retryRequest(request, new ConnectionClosedException(), 1, null)); } + @Test + public void noRetryForNoRouteToHostException() { + final HttpGet request = new HttpGet("/"); + + Assert.assertFalse(retryStrategy.retryRequest(request, new NoRouteToHostException(), 1, null)); + } + @Test public void noRetryOnSSLFailure() throws Exception { final HttpGet request = new HttpGet("/");