diff --git a/src/main/java/hudson/remoting/Engine.java b/src/main/java/hudson/remoting/Engine.java index aeac760d0..a3779afa7 100644 --- a/src/main/java/hudson/remoting/Engine.java +++ b/src/main/java/hudson/remoting/Engine.java @@ -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 { @@ -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(() -> { @@ -853,6 +836,28 @@ private boolean succeedsWithRetries(SupplierThrowingException 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;