Fix #12536: Handle Ctrl+C on Windows terminals#12538
Open
JackMyers001 wants to merge 1 commit into
Open
Conversation
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.
gnodet
approved these changes
Jul 24, 2026
gnodet
left a comment
Contributor
There was a problem hiding this comment.
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 — callingSystem.exit()from an embedded Maven invocation would terminate the host process. ThedoCreateTerminalmethod already uses the sameembedded()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 likeEncryptInvoker/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
terminalConsumercallback on thefast-terminal-thread— the handler is correctly registered on the real underlying terminal. - The lambda parameter
signalis unused (alwaysINT), consistent with existing patterns inEncryptInvoker,UpgradeInvoker, andShellInvoker.
This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.
Claude Code on behalf of gnodet
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.
Summary
Fixes #12536.
On Windows, JLine handles Ctrl+C as the terminal's
INTsignal. 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
INThandler for Windows terminals that exits with status130. This triggers normal JVM shutdown and its registered cleanup hooks.Please backport this change to
maven-4.0.x.Testing
mvn -Prun-its verifypasses4.0.0-rc-5andmasteron:4.0.0-rc-5andmasteron:3.9.16on all configs listed aboveNo 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:
Note that commits might be squashed by a maintainer on merge.
This may not always be possible but is a best-practice.
mvn verifyto make sure basic checks pass.A more thorough check will be performed on your pull request automatically.
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.