Skip to content

Commit

Permalink
[JENKINS-72163] Retry on initial connection failure occurs in one ent…
Browse files Browse the repository at this point in the history
…rypoint but not the other (#675)
  • Loading branch information
basil authored Oct 12, 2023
1 parent b8c0ef2 commit d76b9dd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/main/java/hudson/remoting/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,7 @@ public void closeRead() throws IOException {
}
events.onDisconnect();
while (true) {
// TODO refactor various sleep statements into a common method

Check warning on line 697 in src/main/java/hudson/remoting/Engine.java

View check run for this annotation

ci.jenkins.io / Open Tasks Scanner

TODO

NORMAL: 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");
Expand Down Expand Up @@ -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

Check warning on line 765 in src/main/java/hudson/remoting/Engine.java

View check run for this annotation

ci.jenkins.io / Open Tasks Scanner

TODO

NORMAL: 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;
}
Expand Down Expand Up @@ -891,6 +899,7 @@ private JnlpEndpointResolver createEndpointResolver(List<String> 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

Check warning on line 902 in src/main/java/hudson/remoting/Engine.java

View check run for this annotation

ci.jenkins.io / Open Tasks Scanner

TODO

NORMAL: refactor various sleep statements into a common method
TimeUnit.SECONDS.sleep(10);
}

Expand All @@ -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

Check warning on line 925 in src/main/java/hudson/remoting/Engine.java

View check run for this annotation

ci.jenkins.io / Open Tasks Scanner

TODO

NORMAL: refactor various sleep statements into a common method
TimeUnit.SECONDS.sleep(10);
events.status(msg+" (retrying:"+retry+")",e);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/hudson/remoting/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ public List<String> 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

Check warning on line 572 in src/main/java/hudson/remoting/Launcher.java

View check run for this annotation

ci.jenkins.io / Open Tasks Scanner

TODO

NORMAL: refactor various sleep statements into a common method
TimeUnit.SECONDS.sleep(10);
// retry
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ public void waitForReady() throws InterruptedException {
try {
int retries = 0;
while (true) {
// TODO refactor various sleep statements into a common method

Check warning on line 383 in src/main/java/org/jenkinsci/remoting/engine/JnlpAgentEndpointResolver.java

View check run for this annotation

ci.jenkins.io / Open Tasks Scanner

TODO

NORMAL: refactor various sleep statements into a common method
Thread.sleep(1000 * 10);
try {
// Jenkins top page might be read-protected. see http://www.nabble
Expand Down

0 comments on commit d76b9dd

Please sign in to comment.