Fix input stream piping in Forker (Issue #882)#2855
Open
dorodb-web22 wants to merge 3 commits intoscalacenter:mainfrom
Open
Fix input stream piping in Forker (Issue #882)#2855dorodb-web22 wants to merge 3 commits intoscalacenter:mainfrom
dorodb-web22 wants to merge 3 commits intoscalacenter:mainfrom
Conversation
tgodzik
reviewed
Jan 22, 2026
| opts.env.toMap, | ||
| writeToStdIn = outputStream => { | ||
| val mainCancellable = goobleInput(outputStream) | ||
| val thread = new Thread { |
Contributor
There was a problem hiding this comment.
Are you able to add some tests? I can confirm that this is fixing the issues at hand
Author
There was a problem hiding this comment.
I've added the tests as requested.
The test cases verify that the blocking reader thread approach fixes the stdin readline issue, covering:
- Input forwarding without data loss
- No indefinite waiting when reading from stdin
- Compatibility with forker-realib patterns
4)Standard I/O patterns work correctly
Could you approve the workflow run so CI can execute the tests? Thanks!
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.
Fixes #882.
Problem
Reading input from
stdin(e.g. usingreadInt) was flaky. The issue was that we were usingInputStream.available()to poll for data. This method isn't reliable; it often returns 0 even when data is waiting, causing the process to drop input or wait indefinitely.Solution
I've replaced the polling mechanism with a standard blocking reader thread.
gobbleInputloop that relied onavailable().read()call. As soon as any bytes appear, they are immediately piped to the forked process's standard input.This ensures input is forwarded immediately on all platforms.
Verification
Forker.scalachanges follow standard I/O patterns.