Skip to content

Commit

Permalink
Do not synchronize and add a timeout for "bad" locations
Browse files Browse the repository at this point in the history
  • Loading branch information
laeubi committed Aug 23, 2023
1 parent 6809979 commit 9a9f01d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
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

0 comments on commit 9a9f01d

Please sign in to comment.