Skip to content

Commit cb76203

Browse files
committed
[JENKINS-45142] Retry connections after getting SocketTimeoutException.
1 parent e9b59c6 commit cb76203

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/main/java/org/kohsuke/github/Requester.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.net.HttpURLConnection;
3737
import java.net.MalformedURLException;
3838
import java.net.ProtocolException;
39+
import java.net.SocketTimeoutException;
3940
import java.net.URL;
4041
import java.net.URLEncoder;
4142
import java.util.ArrayList;
@@ -57,6 +58,7 @@
5758
import org.apache.commons.lang.StringUtils;
5859

5960
import static java.util.Arrays.asList;
61+
import java.util.logging.Level;
6062
import static java.util.logging.Level.*;
6163
import static org.kohsuke.github.GitHub.MAPPER;
6264

@@ -579,6 +581,10 @@ private void setRequestMethod(HttpURLConnection uc) throws IOException {
579581
}
580582

581583
private <T> T parse(Class<T> type, T instance) throws IOException {
584+
return parse(type, instance, 2);
585+
}
586+
587+
private <T> T parse(Class<T> type, T instance, int timeouts) throws IOException {
582588
InputStreamReader r = null;
583589
int responseCode = -1;
584590
String responseMessage = null;
@@ -609,6 +615,10 @@ private <T> T parse(Class<T> type, T instance) throws IOException {
609615
// to preserve backward compatibility
610616
throw e;
611617
} catch (IOException e) {
618+
if (e instanceof SocketTimeoutException && timeouts > 0) {
619+
LOGGER.log(Level.INFO, "timed out accessing " + uc.getURL() + "; will try " + timeouts + " more time(s)", e);
620+
return parse(type, instance, timeouts - 1);
621+
}
612622
throw new HttpException(responseCode, responseMessage, uc.getURL(), e);
613623
} finally {
614624
IOUtils.closeQuietly(r);

0 commit comments

Comments
 (0)