Skip to content

Backport "Fix "Fix Ctrl-C Handling in the REPL"" to 3.8.4#25874

Merged
WojciechMazur merged 1 commit intorelease-3.8.4from
release-3.8.4_backport-25835
Apr 20, 2026
Merged

Backport "Fix "Fix Ctrl-C Handling in the REPL"" to 3.8.4#25874
WojciechMazur merged 1 commit intorelease-3.8.4from
release-3.8.4_backport-25835

Conversation

@WojciechMazur
Copy link
Copy Markdown
Contributor

Backports #25835 to the 3.8.4-RC2.

PR submitted by the release tooling.

Follow-up from #25782. This PR lets
us get the best of both worlds: `Ctrl-C` handling works even in the
subprocess scenario, and `System.in.read()` works too.

Basically rather than having two threads reading from `System.in` at the
same time, we wrap `System.in` in our own wrapper such that we can peek
at it without dropping the characters we read on the floor. This lets us
check for Ctrl-C from the REPL infrastructure while still ensuring that
all System.in characters end up being correctly sent to any
`System.in.read()` calls made by user code in the REPL

I haven't looked at the JShell sources since that is prohibited, but it
seems they do a similar sort of wrapping, as empirically JShell is able
to handle `System.in.read` while still capturing Ctrl-C and handling
that appropriately as well, and `System.in` in JShell is a wrapper input
rather than a raw `java.io.BufferedInputStream`

```scala
jshell> System.in
$1 ==> jdk.jshell.execution.Util$1@31a5c39e
```

## How much have you relied on LLM-based tools in this contribution?

Extensively

## How was the solution tested?

Tested manually via `./mill repl`. 

1. Verified that without this PR `Ctrl-C` handling does not work due to
the REPL running in a subprocess, with this PR Ctrl-C is properly
caught.
2. Also verified that without this PR, `System.in.read()` in the REPL
returns `-1`, whereas with this PR `System.in.read()` in the REPL
correctly prompts the user to enter input, and prints the ascii code of
the character entered

Also verified the original `def askQuestion` scenario which now seems to
work
[Cherry-picked 7fd3dcd]
Base automatically changed from release-3.8.4_backport-25659 to release-3.8.4 April 20, 2026 13:13
@WojciechMazur WojciechMazur merged commit 814ff92 into release-3.8.4 Apr 20, 2026
70 checks passed
@WojciechMazur WojciechMazur deleted the release-3.8.4_backport-25835 branch April 20, 2026 13:13
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.

2 participants