Skip to content

Fix input stream piping in Forker (Issue #882)#2855

Open
dorodb-web22 wants to merge 3 commits intoscalacenter:mainfrom
dorodb-web22:fix/issue-882
Open

Fix input stream piping in Forker (Issue #882)#2855
dorodb-web22 wants to merge 3 commits intoscalacenter:mainfrom
dorodb-web22:fix/issue-882

Conversation

@dorodb-web22
Copy link

Fixes #882.

Problem

Reading input from stdin (e.g. using readInt) was flaky. The issue was that we were using InputStream.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.

  • Removed: The gobbleInput loop that relied on available().
  • Added: A dedicated thread that blocks on a standard 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

  • Verified locally that the blocking approach forwards input correctly without flakiness.
  • Forker.scala changes follow standard I/O patterns.

opts.env.toMap,
writeToStdIn = outputStream => {
val mainCancellable = goobleInput(outputStream)
val thread = new Thread {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you able to add some tests? I can confirm that this is fixing the issues at hand

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tgodzik

I've added the tests as requested.
The test cases verify that the blocking reader thread approach fixes the stdin readline issue, covering:

  1. Input forwarding without data loss
  2. No indefinite waiting when reading from stdin
  3. 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!

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.

Reading input from application doesn't work

2 participants