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

Do not synchronize and add a timeout for "bad" locations #2727

Merged
merged 1 commit into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

public interface HttpTransportFactory {

static final long TIMEOUT_SECONDS = Long.getLong("tycho.http.transport.timeout", 30);

HttpTransport createTransport(URI uri);

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.util.List;
import java.util.Locale;
import java.util.Map;
Expand Down Expand Up @@ -137,7 +138,7 @@ public void close() {
}

private HttpResponse<InputStream> performGet() throws IOException, InterruptedException {
HttpRequest request = builder.GET().build();
HttpRequest request = builder.GET().timeout(Duration.ofSeconds(TIMEOUT_SECONDS)).build();
try {
return client.send(request, BodyHandlers.ofInputStream());
} catch (IOException e) {
Expand All @@ -154,7 +155,8 @@ private HttpResponse<InputStream> performGet() throws IOException, InterruptedEx
@Override
public Response<Void> head() throws IOException {
try {
HttpResponse<Void> response = client.send(builder.method("HEAD", null).build(),
HttpResponse<Void> response = client.send(
builder.method("HEAD", null).timeout(Duration.ofSeconds(TIMEOUT_SECONDS)).build(),
BodyHandlers.discarding());
return new ResponseImplementation<>(response) {
@Override
Expand Down Expand Up @@ -239,8 +241,11 @@ public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {

}
};
client = HttpClient.newBuilder().followRedirects(Redirect.NEVER).proxy(proxySelector).build();
clientHttp1 = HttpClient.newBuilder().version(Version.HTTP_1_1).followRedirects(Redirect.NEVER)
client = HttpClient.newBuilder().connectTimeout(Duration.ofMinutes(TIMEOUT_SECONDS))
.followRedirects(Redirect.NEVER)
.proxy(proxySelector).build();
clientHttp1 = HttpClient.newBuilder().connectTimeout(Duration.ofMinutes(TIMEOUT_SECONDS))
.version(Version.HTTP_1_1).followRedirects(Redirect.NEVER)
.proxy(proxySelector).build();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ private IStatus reportStatus(IStatus status, OutputStream target) {
}

@Override
public synchronized InputStream stream(URI toDownload, IProgressMonitor monitor)
throws FileNotFoundException, CoreException, AuthenticationFailedException {
public InputStream stream(URI toDownload, IProgressMonitor monitor)
throws FileNotFoundException, CoreException, AuthenticationFailedException {
if (DEBUG_REQUESTS) {
logger.debug("Request stream for " + toDownload);
}
Expand Down
Loading