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

Revert #544 so that RealJenkinsRule shuts down cleanly on Windows #559

Merged
merged 2 commits into from
Mar 7, 2023

Conversation

dwnusbaum
Copy link
Member

@dwnusbaum dwnusbaum commented Mar 6, 2023

Based on CI build failures in jenkinsci/workflow-cps-plugin#669 (see for example this test output), I am suspicious that beyond the lack of shutdown-related log messages on older versions of Jenkins, #544 might not shut down Jenkins cleanly on Windows, in particular I think Jenkins.cleanUp might not run and terminators may be skipped.

This PR injects an ItemListener dynamically into Jenkins using ExtensionList.add that writes a file in onBeforeShutdown, which is called by Jenkins.cleanUp, and after the restart we check for the existence of this file. Maybe there is something else we can already observe without needing this, but without LoggerRule I couldn't think of anything obvious.

RealJenkinsRuleTest.restart passes for me locally on MacOS with this PR.

EDIT: The tests confirmed my suspicions, so this PR now reverts #544 so that RealJenkinsRule shuts down cleanly on Windows.

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

@dwnusbaum dwnusbaum changed the title Enhance RealJenkinsRule.restart to check that Jenkins.cleanUp runs Enhance RealJenkinsRuleTest.restart to check that Jenkins.cleanUp runs Mar 6, 2023
@dwnusbaum
Copy link
Member Author

Hmm the CI build does fail on Windows but not on Linux. @jglick was #544 necessary to fix an issue in some scenario, or was it just a simplification that could be reverted? As far as I can tell, that PR causes RealJenkinsRule.stopJenkins to not stop Jenkins cleanly on Windows, even when running Jenkins 2.391+.

@jglick
Copy link
Member

jglick commented Mar 6, 2023

It could be reverted I think, but I would like to know why stopping the process does not cause terminators to run—if true, that certainly sounds like a bug?

@dwnusbaum
Copy link
Member Author

dwnusbaum commented Mar 7, 2023

I would like to know why stopping the process does not cause terminators to run—if true, that certainly sounds like a bug?

Discussion in JDK-4485742 and linked tickets indicates that Process.destroy terminates the process in a way that bypasses Java shutdown hooks on Windows (which is what Winstone uses to trigger cleanup), and that this will not be changed due to backwards compatibility implications. Looking at JDK source code, ProcessHandle.destroy seems to use the same native Windows API calls (compare this to this), so I assume it has the same behavior.

EDIT: Also, as far as I can tell, Process.supportsNormalTermination() and ProcessHandle.supportsNormalTermination() both return false on Windows.

@jglick
Copy link
Member

jglick commented Mar 7, 2023

Also JDK-8056139. Hmm, that is unfortunate. We could fully revert #544, or continue to send SIGTERM on Linux and just use the special /exit endpoint on Windows.

@dwnusbaum
Copy link
Member Author

dwnusbaum commented Mar 7, 2023

Is there any reason to prefer ProcessHandle.destroy in cases where ProcessHandle.supportsNormalTermination() returns true? If not, I guess just fully reverting #544 is simplest so that there is only one code path.

@jglick
Copy link
Member

jglick commented Mar 7, 2023

any reason to prefer ProcessHandle.destroy

Merely to avoid a gratuitous use of a different code path than what would often be used in a realistic context. I agree that having two modes is more confusing that it would be worth, so reverting #544 would be the simplest fix. Feel free to file that (it sounds like you already have some downstream work which would verify the effectiveness).

This reverts commit fb39b60, reversing
changes made to eb817ec.
@dwnusbaum dwnusbaum changed the title Enhance RealJenkinsRuleTest.restart to check that Jenkins.cleanUp runs Revert #544 so that RealJenkinsRule shuts down cleanly on Windows Mar 7, 2023
@dwnusbaum
Copy link
Member Author

dwnusbaum commented Mar 7, 2023

Ok, I pushed the revert to this PR.

it sounds like you already have some downstream work which would verify the effectiveness

I think the updates to RealJenkinsRuleTest.restart here are enough the validate the fix and prevent future regressions.

@dwnusbaum dwnusbaum marked this pull request as ready for review March 7, 2023 17:04
@jglick
Copy link
Member

jglick commented Mar 7, 2023

the updates to RealJenkinsRuleTest.restart here are enough the validate the fix

You mean, when run on Windows.

@jglick jglick added the bug label Mar 7, 2023
@jglick jglick enabled auto-merge March 7, 2023 17:15
@dwnusbaum
Copy link
Member Author

You mean, when run on Windows.

Yes, but the CI build here does test against Windows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants