Forward run stdin via blocking read instead of polling available()#2936
Open
jozanek wants to merge 4 commits into
Open
Forward run stdin via blocking read instead of polling available()#2936jozanek wants to merge 4 commits into
jozanek wants to merge 4 commits into
Conversation
Contributor
Author
|
@tgodzik feel free to rerun, should not be connected to my changes. |
tgodzik
reviewed
Jun 4, 2026
| * `opts.in` is nailgun's NGInputStream, whose `available()` returns 0 even | ||
| * while data is in flight, which silently drops input. Mirrors the blocking | ||
| * `readOutput` threads used below for stdout/stderr. */ | ||
| val thread = new Thread("bloop-forker-stdin") { |
Contributor
There was a problem hiding this comment.
I wonder whether we could reuse any of the monix utilities instead of using Threads directly.
ExecutionContext.ioScheduler.scheduleWithFixedDelay(duration, duration) { wouldn't block as well?
Contributor
|
Were you able to confirm that it works when using |
Contributor
Author
|
Hey Tomek! You are right, the test wasn't sufficient. The issue is in snailgun, but since it is not maintained anymore, I am thinking about moving it completely under bloop (500 LOC) and then try to reduce it as much as possible. |
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.
Root cause
bloop runnever delivered usable stdin to the forked application, and it broke on two layers:Forkerforwarded stdin with a 50ms poll loop gated onopts.in.available() > 0. On the CLI pathopts.inis nailgun'sNGInputStream, whoseavailable()returns 0 while data is in flight, so the loop never read — and never drove nailgun's demand protocol, so the server never even asked the client for input.readLine()and forwarded each line without its newline, so the forked app'sreadInt/readLine/Scannernever saw a delimiter and blocked forever. It also NPE'd on EOF (line.length()was checked beforeline == null).Changes
Forker: replace theavailable()poll with a blocking read on a monixTaskrun onExecutionContext.ioScheduler(the same blocking-I/O idiom used byBspServer/TestServer). This drives nailgun's demand protocol so the server actually requests and reads stdin.snailgundependency (unmaintained, no release since 2023) and replace it with a minimal, bloop-native nailgun client underbloop.rifle.internal.nailgun, trimmed to what bloop uses (daemon-thread path only,BloopRifleLoggerdirectly). Its stdin forwarder sends each line with its newline and handles EOF. Adapted from snailgun (Apache-2.0, attributed in-file).BloopRifleLogger.nailgunLoggeradapter.Verification
RunSpec.canRunApplicationThatReadsStdinWithoutAvailableBytes: a regression test using anInputStreamwhoseavailable()always returns 0 (simulatingNGInputStream). Fails on the old poll loop (15s timeout), passes on the blocking read.bloop runof an app doingprintln(StdIn.readInt() + StdIn.readInt())now reads1/2and prints3(previously hung indefinitely).