Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix websocket connection retries logic #771

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions src/main/java/hudson/remoting/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -821,11 +821,11 @@ public void closeRead() throws IOException {
* @return true if the condition succeeded, false if the condition failed and the timeout was reached
* @throws InterruptedException if the thread was interrupted while waiting.
*/
private boolean succeedsWithRetries(SupplierThrowingException<Boolean> condition) throws InterruptedException {
private boolean succeedsWithRetries(java.util.concurrent.Callable<Boolean> condition) throws InterruptedException {
var exponentialRetry = new ExponentialRetry(noReconnectAfter);
while (exponentialRetry != null) {
try {
if (condition.get()) {
if (condition.call()) {
return true;
}
} catch (Exception x) {
Expand Down Expand Up @@ -903,19 +903,13 @@ ExponentialRetry next(EngineListenerSplitter events) throws InterruptedException
events.status("Bailing out after " + DurationFormatter.format(next.timeout));
return null;
} else {
var delaySeconds = next.delay.toSeconds();
events.status("Waiting " + delaySeconds + " seconds before retry");
TimeUnit.SECONDS.sleep(delaySeconds);
events.status("Waiting " + DurationFormatter.format(next.delay) + " before retry");
TimeUnit.SECONDS.sleep(next.delay.toSeconds());
Vlatombe marked this conversation as resolved.
Show resolved Hide resolved
}
return next;
}
}

@FunctionalInterface
private interface SupplierThrowingException<T> {
T get() throws Exception;
}

private void reconnect() {
try {
events.status("Performing onReconnect operation.");
Expand Down
Loading