Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0f21eba

Browse filesBrowse files
authored
Merge pull request hub4j#359 from jglick/SocketTimeoutException-JENKINS-45142
[JENKINS-45142] Retry connections after getting SocketTimeoutException
2 parents e9b59c6 + cb76203 commit 0f21eba
Copy full SHA for 0f21eba

File tree

Expand file treeCollapse file tree

1 file changed

+10
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+10
-0
lines changed

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

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/Requester.java
+10Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.