Skip to content

Fix #12536: Handle Ctrl+C on Windows terminals#12538

Open
JackMyers001 wants to merge 1 commit into
apache:masterfrom
JackMyers001:fix-12536-handle-ctrl-c-on-windows
Open

Fix #12536: Handle Ctrl+C on Windows terminals#12538
JackMyers001 wants to merge 1 commit into
apache:masterfrom
JackMyers001:fix-12536-handle-ctrl-c-on-windows

Conversation

@JackMyers001

@JackMyers001 JackMyers001 commented Jul 24, 2026

Copy link
Copy Markdown

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.

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 gnodet left a comment

Copy link
Copy Markdown
Contributor

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

@gnodet gnodet added this to the 4.0.0-rc-6 milestone Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Maven 4 - Ctrl+C does not terminate child processes on Windows

2 participants