[JENKINS-35272] Launcher's afterDisconnect() method is called twice#26402
Open
Anvarjon7 wants to merge 1 commit intojenkinsci:masterfrom
Open
[JENKINS-35272] Launcher's afterDisconnect() method is called twice#26402Anvarjon7 wants to merge 1 commit intojenkinsci:masterfrom
Anvarjon7 wants to merge 1 commit intojenkinsci:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #17204
Takes over the work from #26188 to fix JENKINS-35272, addressing the Windows test failure that caused the previous attempt to be reverted.
Root Cause
When an agent disconnects,
SlaveComputer.javaexecuteslauncher.afterDisconnect()from both the explicitdisconnect()thread and theonClosed()channel listener. This caused duplicate teardown actions, such as shutting down VMs twice.Why the Previous Fix Failed on Windows (
UnsupportedRemotingAgentTest)The previous attempt used a non-blocking
AtomicBooleanto prevent the second call. However, if the test framework triggered a disconnect while the background Remoting thread was already killing the process, the test framework's thread would instantly returnfalse(thinking the job was done) and proceed to the JUnit@TempDircleanup phase. On Windows, this caused anAccessDeniedExceptionbecause the background thread was still holding the file lock onunsupported-agent.jarwhile killing the process.The Solution
Instead of an
AtomicBoolean, this PR introduces asynchronized(disconnectLock)block around the execution flag.afterDisconnect()is only ever executed once.Testing done
Verified locally on Windows native CLI. Executed
mvn test -Dtest=UnsupportedRemotingAgentTestwhich now consistently passes, confirming the file-lock race condition is fully resolved and the asynchronous disconnect sequence safely completes before the test teardown.Screenshots (UI changes only)
N/A
Proposed changelog entries
Proposed changelog category
/label bug
Proposed upgrade guidelines
N/A
Submitter checklist
@Restrictedor have@since TODOJavadocs, as appropriate.@Deprecated(since = "TODO")or@Deprecated(forRemoval = true, since = "TODO"), if applicable.evalto ease future introduction of Content Security Policy (CSP) directives.Desired reviewers
@jenkinsci/core-pr-reviewers
Before the changes are marked as
ready-for-merge:Maintainer checklist
upgrade-guide-neededlabel is set and there is a Proposed upgrade guidelines section in the pull request title (see example).lts-candidateto be considered.