[JENKINS-35272] Prevent duplicate invocation of Launcher.afterDisconnect#26142
[JENKINS-35272] Prevent duplicate invocation of Launcher.afterDisconnect#26142RajThak-998 wants to merge 11 commits intojenkinsci:masterfrom
Conversation
|
/label bug |
|
Please don't sabotage yourself as a new contributor. Be sure that you:
As far as I can tell, you skipped several of those items in your pull request. |
There was a problem hiding this comment.
Pull request overview
This PR aims to fix JENKINS-35272 by preventing duplicate invocations of Launcher.afterDisconnect() during agent disconnection. The solution introduces a volatile boolean flag with double-checked locking to ensure the method is called exactly once per connection lifecycle.
Changes:
- Added
afterDisconnectCalledflag to track whetherafterDisconnect()has been called - Introduced
safeAfterDisconnect()method implementing double-checked locking pattern - Replaced direct
afterDisconnect()calls withsafeAfterDisconnect()in disconnect paths - Added flag reset logic when establishing new connections
Comments suppressed due to low confidence (1)
core/src/main/java/hudson/slaves/SlaveComputer.java:668
- The safeAfterDisconnect() method is called at line 659, but then launcher.afterDisconnect() is still being called directly at line 661. This defeats the purpose of the fix and will still result in duplicate calls to afterDisconnect(). The direct call at lines 660-668 should be removed since safeAfterDisconnect() already handles calling afterDisconnect() with proper error handling.
safeAfterDisconnect(); // changed from direct call to safe method to avoid multiple calls
try {
launcher.afterDisconnect(SlaveComputer.this, taskListener);
} catch (Throwable t) {
LogRecord lr = new LogRecord(Level.SEVERE,
"Launcher {0}'s afterDisconnect method propagated an exception when {1}'s connection was closed: {2}");
lr.setThrown(t);
lr.setParameters(new Object[]{launcher, SlaveComputer.this.getName(), t.getMessage()});
logger.log(lr);
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| synchronized (this){ | ||
| if(!afterDisconnectCalled){ | ||
| afterDisconnectCalled = true; | ||
| try{ |
There was a problem hiding this comment.
Add spaces around braces to follow standard Java formatting conventions. This block should be formatted as 'try {' instead of 'try{'.
| try{ | |
| try { |
| afterDisconnectCalled = true; | ||
| try{ | ||
| launcher.afterDisconnect(SlaveComputer.this, taskListener); | ||
| } catch (Throwable t){ |
There was a problem hiding this comment.
Add space before opening brace to follow standard Java formatting conventions. It should be '} catch (Throwable t) {' instead of '} catch (Throwable t){'.
| } catch (Throwable t){ | |
| } catch (Throwable t) { |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Please restore the pull request template and provide all the information that it requests. You didn't use the pull request template and haven't provided the required information that is requested in the pull request template.
You've provided no description that you were able to duplicate the issue. Describe the testing that showed your change is necessary.
You didn't follow the guide. Please read it carefully and make the necessary corrections to your pull request.
You don't describe how you tested interactively. Please describe the interactive testing you performed.
The change contains no automated tests. Please provide automated tests.
You ignored my comment that you might be sabotaging yourself and did not correct the issues. That makes reviewers work harder and that tends to make reviewers less willing to interact with you and more likely to close your pull request. |
|
Thanks for the feedback and apologies for missing the PR template and testing I have updated the pull request description to fully follow the template, Thanks for the guidance. |
The checks are failing because you didn't follow the contributing guide. The guide notes how you can check and fix the formatting of your changes before you submit the pull request. I'm placing this pull request in "Draft" so that other maintainers do not waste their time reviewing it when it is not yet ready to be reviewed. When you've completed all the items in the list of actions that I provided, you can mark the pull request as "ready for review". |
|
Please take a moment and address the merge conflicts of your pull request. Thanks! |
|
This has been in draft for two weeks with no further progress from the submitter. There is an unresolved merge conflict. I plan to close this after a 24 hour waiting period if there is no further progress on it. |
Fixes #JENKINS-35272
Summary
Ensure that
SlaveComputer#afterDisconnectis invoked only once for a singleagent disconnect event.
Problem
When a Jenkins agent disconnects unexpectedly (for example due to network loss
or abrupt process termination), the
afterDisconnectcallback could be invokedmultiple times for the same disconnect event. This could result in duplicate
cleanup logic being executed and inconsistent agent state handling.
Reproduction steps
dropping the network connection).
afterDisconnectmay be invoked more than once for the samedisconnect.
Testing done
Interactive testing
afterDisconnectis now invokedonly once per disconnect event.
Automated tests
Automated tests are being added to cover repeated disconnect scenarios and
to demonstrate that
afterDisconnectis invoked only once. The tests willfail without this change and pass with it.
Screenshots (UI changes only)
N/A
Proposed changelog entries
Proposed changelog category
/label bug
Proposed upgrade guidelines
N/A
Submitter checklist