GeezerVison is showing github.com — Fix #12536: Handle Ctrl+C on Windows terminals by JackMyers001 · Pull Request #12538 · apache/maven
Conversation
Summary
Fixes #12536.
On Windows, JLine handles Ctrl+C as the terminal's INT signal. Without an explicit handler, the standalone Maven JVM does not follow its normal interrupt termination path and Maven's shutdown hooks do not run, which can leave long-running child processes alive.
This change registers an INT handler for Windows terminals that exits with status 130. This triggers normal JVM shutdown and its registered cleanup hooks.
Please backport this change to maven-4.0.x.
Testing
mvn -Prun-its verify passes
- Confirmed issue in
4.0.0-rc-5 and master on:
- Windows 11 with PowerShell in Windows Terminal
- Windows 11 with Git Bash in Windows Terminal
- Confirmed issue is not present in
4.0.0-rc-5 and master on:
- macOS 26 with Fish in Ghostty
- Arch Linux with Fish in Ghostty
- Confirmed issue is not present in
3.9.16 on all configs listed above
- Confirmed issue is not present with this patch on all configs listed above
No automated regression test is included because the failure requires a real Windows terminal running Maven and a way to send a Ctrl+C event to that console.
Checklist
Following this checklist to help us incorporate your
contribution quickly and easily:
- Your pull request should address just one issue, without pulling in other changes.
- Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- Each commit in the pull request should have a meaningful subject line and body.
Note that commits might be squashed by a maintainer on merge.
- Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied.
This may not always be possible but is a best-practice.
- Run
mvn verify to make sure basic checks pass.
A more thorough check will be performed on your pull request automatically.
- You have run the Core IT successfully.
If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.
To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
On Windows, JLine handles Ctrl+C as the terminal's `INT` signal. Without
an explicit handler, the standalone Maven JVM does not follow its normal
interrupt termination path and Maven's shutdown hooks do not run, which
can leave long-running child processes alive.
This change registers an `INT` handler for Windows terminals that exits
with status `130`. This triggers normal JVM shutdown and its registered
cleanup hooks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
Clean, minimal, and correctly scoped fix for a real Windows-specific Ctrl+C regression in Maven 4. The approach is sound and consistent with existing codebase patterns.
Key observations:
- The
!context.invokerRequest.embedded() guard is essential and correctly placed — calling System.exit() from an embedded Maven invocation would terminate the host process. The doCreateTerminal method already uses the same embedded() check.
- Exit code 130 (128 + SIGINT=2) follows the Unix convention for signal-terminated processes and is properly extracted into a named constant.
- The fix is correctly gated to Windows only via
OSUtils.IS_WINDOWS. On Unix/macOS, the OS delivers SIGINT to the JVM natively. On Windows, JLine puts the terminal into raw mode and consumes Ctrl+C as console input before the JVM sees it.
System.exit() is appropriate here (vs. Thread.currentThread().interrupt() used in other handlers like EncryptInvoker/ShellInvoker) because the goal is full JVM termination with shutdown hooks for the main build invocation.
Two minor notes (non-blocking):
- The signal handler runs inside the
terminalConsumer callback on the fast-terminal-thread — the handler is correctly registered on the real underlying terminal.
- The lambda parameter
signal is unused (always INT), consistent with existing patterns in EncryptInvoker, UpgradeInvoker, and ShellInvoker.
This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.
Claude Code on behalf of gnodet
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
|
@gnodet Please assign appropriate label to PR according to the type of change.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
gnodet
added a commit
that referenced
this pull request
Jul 27, 2026
Backport of #12538. On Windows, JLine puts the terminal into raw mode
and consumes Ctrl+C as console input before the JVM sees it. This
registers a Terminal.Signal.INT handler that calls System.exit(130) to
restore proper Ctrl+C behavior, guarded by IS_WINDOWS and !embedded().
Closes #12550
Reviewers
gnodet
gnodet approved these changes
Uh oh!
There was an error while loading. Please reload this page.
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.
|