Skip to content

Commit 0f4a672

Browse files
committed
Only fetch checksums for final gradle releases during build
This is a follow up to eclipse-jdtls#2775 I frequently experience build failures due to connection errors. After some debugging with wireshark, netstat and `-Djdk.httpclient.HttpClient.log=all` I suspect that I'm getting rate throttled. Somewhere between 150 and 200 requests, the connections either get closed by the remote or almost stall. This excludes nightly, snapshot, rc and broken releases, which would mitigate the issue somewhat. The biggest impact has cutting out RC releases: total versions: 386 without nightly: 385 without RCs: 173 without broken: 172 Note that this still doesn't completely fix the issue for me, but it helsp reduce the chance for it happening.
1 parent fe0ac4c commit 0f4a672

File tree

1 file changed

+12
-30
lines changed

1 file changed

+12
-30
lines changed

org.eclipse.jdt.ls.core/pom.xml

+12-30
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@
5252
import groovy.json.JsonOutput
5353
5454
import java.net.http.HttpClient
55+
import java.net.http.HttpClient.Redirect
5556
import java.net.http.HttpRequest
5657
import java.net.http.HttpResponse.BodyHandlers
5758
import java.util.concurrent.CompletableFuture
5859
import java.util.stream.Collectors;
5960
60-
6161
def checksumsFile = new File(project.basedir.absolutePath, "gradle/checksums/checksums.json")
6262
if (System.getProperty("eclipse.jdt.ls.skipGradleChecksums") != null && checksumsFile.exists()) {
6363
println "Skipping gradle wrapper validation checksums ..."
@@ -77,42 +77,24 @@
7777
String wrapperChecksumUrl;
7878
String sha256
7979
}
80-
HttpClient client = HttpClient.newHttpClient()
80+
81+
HttpClient client = HttpClient.newBuilder()
82+
.followRedirects(Redirect.NORMAL)
83+
.build();
8184
def futures = []
8285
versions.each {
83-
if (it.wrapperChecksumUrl == null) {
86+
if (it.wrapperChecksumUrl == null || it.nightly || it.snapshot || it.rcFor != "" || it.broken) {
8487
return
8588
}
8689
HttpRequest request = HttpRequest.newBuilder().uri(URI.create(it.wrapperChecksumUrl)).build()
87-
futures.add(client.sendAsync(request, BodyHandlers.ofString()).thenApply { response ->
88-
if (response.statusCode() == 301) {
89-
String newUrl = response.headers().firstValue("location").orElse(null)
90-
if (newUrl != null) {
91-
HttpRequest newRequest = HttpRequest.newBuilder()
92-
.uri(URI.create(newUrl))
93-
.build()
94-
try {
95-
String sha256 = client.send(newRequest, BodyHandlers.ofString()).body()
96-
return new Checksum(wrapperChecksumUrl: it.wrapperChecksumUrl, sha256: sha256)
97-
} catch (IOException | InterruptedException e) {
98-
return null
99-
}
100-
} else {
101-
return null
102-
}
103-
} else {
104-
// Return the body of the original response
105-
return new Checksum(wrapperChecksumUrl: it.wrapperChecksumUrl, sha256: response.body())
106-
}
107-
})
90+
future = client.sendAsync(request, BodyHandlers.ofString()).thenApply { response ->
91+
return new Checksum(wrapperChecksumUrl: it.wrapperChecksumUrl, sha256: response.body())
92+
}
93+
futures.add(future)
10894
}
10995
110-
def checksums = CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]))
111-
.thenApply { v ->
112-
futures.stream().map({ f ->
113-
f.join()
114-
}).collect(Collectors.toList())
115-
}.get()
96+
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).get()
97+
def checksums = futures.stream().map({ f -> f.join() }).collect(Collectors.toList())
11698
11799
def json = JsonOutput.toJson(checksums)
118100
checksumsFile.write(JsonOutput.prettyPrint(json))

0 commit comments

Comments
 (0)