diff --git a/src/main/java/hudson/remoting/Engine.java b/src/main/java/hudson/remoting/Engine.java index 5fcf143d6..bb266028b 100644 --- a/src/main/java/hudson/remoting/Engine.java +++ b/src/main/java/hudson/remoting/Engine.java @@ -694,6 +694,7 @@ public void closeRead() throws IOException { } events.onDisconnect(); while (true) { + // TODO refactor various sleep statements into a common method TimeUnit.SECONDS.sleep(10); // 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"); @@ -758,11 +759,18 @@ private void innerRun(IOHub hub, SSLContext context, ExecutorService service) { final JnlpAgentEndpoint endpoint; try { endpoint = resolver.resolve(); - } catch (Exception e) { - if (Boolean.getBoolean(Engine.class.getName() + ".nonFatalJnlpAgentEndpointResolutionExceptions")) { - events.status("Could not resolve JNLP agent endpoint", e); + } catch (IOException e) { + if (!noReconnect) { + events.status("Could not locate server among " + candidateUrls + "; waiting 10 seconds before retry", e); + // TODO refactor various sleep statements into a common method + TimeUnit.SECONDS.sleep(10); + continue; } else { - events.error(e); + if (Boolean.getBoolean(Engine.class.getName() + ".nonFatalJnlpAgentEndpointResolutionExceptions")) { + events.status("Could not resolve JNLP agent endpoint", e); + } else { + events.error(e); + } } return; } @@ -891,6 +899,7 @@ private JnlpEndpointResolver createEndpointResolver(List jenkinsUrls) { private void onConnectionRejected(String greeting) throws InterruptedException { events.status("reconnect rejected, sleeping 10s: ", new Exception("The server rejected the connection: " + greeting)); + // TODO refactor various sleep statements into a common method TimeUnit.SECONDS.sleep(10); } @@ -913,6 +922,7 @@ private Socket connectTcp(@NonNull JnlpAgentEndpoint endpoint) throws IOExceptio if(retry++>10) { throw e; } + // TODO refactor various sleep statements into a common method TimeUnit.SECONDS.sleep(10); events.status(msg+" (retrying:"+retry+")",e); } diff --git a/src/main/java/hudson/remoting/Launcher.java b/src/main/java/hudson/remoting/Launcher.java index 3578e3b13..f29193deb 100644 --- a/src/main/java/hudson/remoting/Launcher.java +++ b/src/main/java/hudson/remoting/Launcher.java @@ -569,6 +569,7 @@ public List parseJnlpArguments() throws ParserConfigurationException, SA System.err.println("Failed to obtain "+ agentJnlpURL); e.printStackTrace(System.err); System.err.println("Waiting 10 seconds before retry"); + // TODO refactor various sleep statements into a common method TimeUnit.SECONDS.sleep(10); // retry } finally { diff --git a/src/main/java/org/jenkinsci/remoting/engine/JnlpAgentEndpointResolver.java b/src/main/java/org/jenkinsci/remoting/engine/JnlpAgentEndpointResolver.java index 6621e1e3c..b127e900a 100644 --- a/src/main/java/org/jenkinsci/remoting/engine/JnlpAgentEndpointResolver.java +++ b/src/main/java/org/jenkinsci/remoting/engine/JnlpAgentEndpointResolver.java @@ -378,6 +378,7 @@ public void waitForReady() throws InterruptedException { try { int retries = 0; while (true) { + // TODO refactor various sleep statements into a common method Thread.sleep(1000 * 10); try { // Jenkins top page might be read-protected. see http://www.nabble