Skip to content

Commit

Permalink
Retry if SocketException
Browse files Browse the repository at this point in the history
  • Loading branch information
v1v committed Jan 23, 2020
1 parent e426237 commit fca179a
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/main/java/org/kohsuke/github/Requester.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@
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;
import java.lang.reflect.Field;
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;
Expand Down Expand Up @@ -902,8 +904,14 @@ private <T> T parse(Class<T> 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);
Expand Down

0 comments on commit fca179a

Please sign in to comment.