Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DownloadUtils doesn't set a timeout, causing downloads to hang if a server doesn't respond #942

Open
Barteks2x opened this issue Feb 26, 2024 · 1 comment

Comments

@Barteks2x
Copy link
Contributor

Barteks2x commented Feb 26, 2024

This is one of java's dumb default:

public static HttpURLConnection connectHttpWithRedirects(URL url, Consumer<HttpURLConnection> setup) throws IOException {
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setInstanceFollowRedirects(true);
con.addRequestProperty("Accept-Encoding", ACCEPT_ENCODING);
setup.accept(con);
con.connect();
if ("http".equalsIgnoreCase(url.getProtocol())) {
int responseCode = con.getResponseCode();
switch (responseCode) {
case HttpURLConnection.HTTP_MOVED_TEMP:
case HttpURLConnection.HTTP_MOVED_PERM:
case HttpURLConnection.HTTP_SEE_OTHER:
String newLocation = con.getHeaderField("Location");
URL newUrl = new URL(newLocation);
if ("https".equalsIgnoreCase(newUrl.getProtocol())) {
// Escalate from http to https.
// This is not done automatically by HttpURLConnection.setInstanceFollowRedirects
// See https://bugs.java.com/bugdatabase/view_bug.do?bug_id=4959149
return connectHttpWithRedirects(newUrl, setup);
}
break;
}
}
return con;
}

if you don't explicitly set a timeout value, it will wait indefinitely for a response that may never arrive.

Normally this works because you either get a response or it fails. But sometimes, in some random cases of network issues, there is no response at all and it will hang, waiting forever for a nonexistent response.

@Barteks2x Barteks2x changed the title MavenArtifactDownloader doesn't set a timeout, causing downloads to hang if a server doesn't respond DownloadUtils doesn't set a timeout, causing downloads to hang if a server doesn't respond Feb 26, 2024
@LexManos
Copy link
Member

Interesting. it depends on the javac implementation it seems. Anyways if you want to set a timeout feel free to submit a pr. I'm fine with whatever as this is a dumb edge case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants