From fca179abab6eb4f9c8305d3f2f0ad635a04542ba Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Thu, 23 Jan 2020 13:33:12 +0000 Subject: [PATCH] Retry if SocketException See https://github.com/github-api/github-api/pull/373 --- src/main/java/org/kohsuke/github/Requester.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/kohsuke/github/Requester.java b/src/main/java/org/kohsuke/github/Requester.java index c7c82f6444..195809c323 100644 --- a/src/main/java/org/kohsuke/github/Requester.java +++ b/src/main/java/org/kohsuke/github/Requester.java @@ -31,6 +31,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.io.InterruptedIOException; import java.io.Reader; import java.io.UnsupportedEncodingException; import java.lang.reflect.Array; @@ -38,6 +39,7 @@ import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.ProtocolException; +import java.net.SocketException; import java.net.SocketTimeoutException; import java.net.URI; import java.net.URISyntaxException; @@ -902,8 +904,14 @@ private T parse(Class type, T instance, int timeouts) throws IOException // don't wrap exception in HttpException to preserve backward compatibility throw e; } catch (IOException e) { - if (e instanceof SocketTimeoutException && timeouts > 0) { - LOGGER.log(INFO, "timed out accessing " + uc.getURL() + "; will try " + timeouts + " more time(s)", e); + if (((e instanceof SocketException && e.getCause() instanceof SocketTimeoutException) + || e instanceof SocketTimeoutException) && timeouts > 0) { + LOGGER.log(INFO, "timed out accessing " + uc.getURL() + ". Sleeping 5 seconds before retrying... ; will try" + timeouts + " more time(s)", e); + try { + Thread.sleep(5000); + } catch (InterruptedException _) { + throw (IOException)new InterruptedIOException().initCause(e); + } return parse(type, instance, timeouts - 1); } throw new HttpException(responseCode, responseMessage, uc.getURL(), e);