Make -w and enter-to-rerun work with subprocess spawning tasks #1645
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.
The basic issue here is that we were not properly closing the input streams generated by spawnSubprocess when
-i
is not passed, in particular the one that pumps input from the proxied stdin to the subprocess. Thus it would survive long past the lifetime of the subprocess, try to pump the proxied stdin into the subprocess's closed stdin, and fail while consuming bytes from the proxied stdin so that other consumers couldn't get at it.The fix is twofold:
checkAvailable = true
for the proxied-stdin-to-subprocess-inputstream pumper so it doesn't block on trying to read from stdin, and instead polls regularly at 2ms intervalsjava.util.function.BooleanSupplier runningCheck
into the pumper that can be used to abort its polling at any point, and configure it so it aborts when its destination subprocess is no longer alive.There's a small race condition where the subprocess may be alive when the check is made, but dead when the stream data is pumped a moment later, and so I add a try-catch around the
InputPumper.run
'sdest.write
call to just quietly discard the input and terminate the pumperAn unrelated change, I also added nice names to all the various threads we're spawning, so it's easier to keep track of them in the
jstack
.Tested manually via
./mill -i dev.run scratch foo.run
. Onmain
without this PR,-i -w
works:But
-w
alone fails:With this PR, both versions succeed: