Skip to content

Commit

Permalink
Spotbugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlatombe committed Oct 24, 2024
1 parent 67e95e2 commit 5953278
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions src/main/java/hudson/remoting/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ public void run() {
}

@SuppressFBWarnings(
value = {"REC_CATCH_EXCEPTION", "URLCONNECTION_SSRF_FD"},
value = {"REC_CATCH_EXCEPTION"},
justification = "checked exceptions were a mistake to begin with; connecting to Jenkins from agent")
private void runWebSocket() {
try {
Expand Down Expand Up @@ -783,24 +783,7 @@ public void closeRead() throws IOException {
client.getProperties().put(ClientProperties.SSL_ENGINE_CONFIGURATOR, sslEngineConfigurator);
}
}
if (!succeedsWithRetries(() -> {
// Unlike JnlpAgentEndpointResolver, we do not use $jenkins/tcpSlaveAgentListener/, as that will be
// a 404 if the TCP port is disabled.
URL ping = new URL(hudsonUrl, "login");
try {
HttpURLConnection conn = (HttpURLConnection) ping.openConnection();
int status = conn.getResponseCode();
conn.disconnect();
if (status == 200) {
return true;
} else {
events.status(ping + " is not ready: " + status);
}
} catch (IOException x) {
events.status(ping + " is not ready", x);
}
return false;
})) {
if (!succeedsWithRetries(this::pingSuccessful)) {
return;
}
if (!succeedsWithRetries(() -> {
Expand Down Expand Up @@ -853,6 +836,28 @@ private boolean succeedsWithRetries(SupplierThrowingException<Boolean> condition
return false;
}

@SuppressFBWarnings(
value = {"URLCONNECTION_SSRF_FD"},
justification = "url is provided by the user, and we are trying to connect to it")
private Boolean pingSuccessful() throws MalformedURLException {
// Unlike JnlpAgentEndpointResolver, we do not use $jenkins/tcpSlaveAgentListener/, as that will be
// a 404 if the TCP port is disabled.
URL ping = new URL(hudsonUrl, "login");
try {
HttpURLConnection conn = (HttpURLConnection) ping.openConnection();
int status = conn.getResponseCode();
conn.disconnect();
if (status == 200) {
return true;
} else {
events.status(ping + " is not ready: " + status);
}
} catch (IOException x) {
events.status(ping + " is not ready", x);
}
return false;
}

private static class ExponentialRetry {
final int factor;
final Instant beginning;
Expand Down

0 comments on commit 5953278

Please sign in to comment.