Skip to content

Commit d76b9dd

Browse files
authoredOct 12, 2023
[JENKINS-72163] Retry on initial connection failure occurs in one entrypoint but not the other (#675)
1 parent b8c0ef2 commit d76b9dd

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed
 

‎src/main/java/hudson/remoting/Engine.java

+14-4
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@ public void closeRead() throws IOException {
694694
}
695695
events.onDisconnect();
696696
while (true) {
697+
// TODO refactor various sleep statements into a common method
697698
TimeUnit.SECONDS.sleep(10);
698699
// Unlike JnlpAgentEndpointResolver, we do not use $jenkins/tcpSlaveAgentListener/, as that will be a 404 if the TCP port is disabled.
699700
URL ping = new URL(hudsonUrl, "login");
@@ -758,11 +759,18 @@ private void innerRun(IOHub hub, SSLContext context, ExecutorService service) {
758759
final JnlpAgentEndpoint endpoint;
759760
try {
760761
endpoint = resolver.resolve();
761-
} catch (Exception e) {
762-
if (Boolean.getBoolean(Engine.class.getName() + ".nonFatalJnlpAgentEndpointResolutionExceptions")) {
763-
events.status("Could not resolve JNLP agent endpoint", e);
762+
} catch (IOException e) {
763+
if (!noReconnect) {
764+
events.status("Could not locate server among " + candidateUrls + "; waiting 10 seconds before retry", e);
765+
// TODO refactor various sleep statements into a common method
766+
TimeUnit.SECONDS.sleep(10);
767+
continue;
764768
} else {
765-
events.error(e);
769+
if (Boolean.getBoolean(Engine.class.getName() + ".nonFatalJnlpAgentEndpointResolutionExceptions")) {
770+
events.status("Could not resolve JNLP agent endpoint", e);
771+
} else {
772+
events.error(e);
773+
}
766774
}
767775
return;
768776
}
@@ -891,6 +899,7 @@ private JnlpEndpointResolver createEndpointResolver(List<String> jenkinsUrls) {
891899

892900
private void onConnectionRejected(String greeting) throws InterruptedException {
893901
events.status("reconnect rejected, sleeping 10s: ", new Exception("The server rejected the connection: " + greeting));
902+
// TODO refactor various sleep statements into a common method
894903
TimeUnit.SECONDS.sleep(10);
895904
}
896905

@@ -913,6 +922,7 @@ private Socket connectTcp(@NonNull JnlpAgentEndpoint endpoint) throws IOExceptio
913922
if(retry++>10) {
914923
throw e;
915924
}
925+
// TODO refactor various sleep statements into a common method
916926
TimeUnit.SECONDS.sleep(10);
917927
events.status(msg+" (retrying:"+retry+")",e);
918928
}

‎src/main/java/hudson/remoting/Launcher.java

+1
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@ public List<String> parseJnlpArguments() throws ParserConfigurationException, SA
569569
System.err.println("Failed to obtain "+ agentJnlpURL);
570570
e.printStackTrace(System.err);
571571
System.err.println("Waiting 10 seconds before retry");
572+
// TODO refactor various sleep statements into a common method
572573
TimeUnit.SECONDS.sleep(10);
573574
// retry
574575
} finally {

‎src/main/java/org/jenkinsci/remoting/engine/JnlpAgentEndpointResolver.java

+1
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ public void waitForReady() throws InterruptedException {
380380
try {
381381
int retries = 0;
382382
while (true) {
383+
// TODO refactor various sleep statements into a common method
383384
Thread.sleep(1000 * 10);
384385
try {
385386
// Jenkins top page might be read-protected. see http://www.nabble

0 commit comments

Comments
 (0)