Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make -w and enter-to-rerun work with subprocess spawning tasks (com-l…
…ihaoyi#1645) 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: 1. Pass in `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 intervals 2. Pass a `java.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`'s `dest.write` call to just quietly discard the input and terminate the pumper An 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`. On `main` without this PR, `-i -w` works: ```bash lihaoyi mill$ ./mill -i dev.run scratch -i -w foo.run [90/647] de.tobiasroeser.mill.vcs.version.VcsVersion.vcsState [647/647] dev.run [44/44] foo.run false Watching for changes to 4 paths... (Enter to re-run, Ctrl-C to exit) <Enter> [44/44] foo.run false Watching for changes to 4 paths... (Enter to re-run, Ctrl-C to exit) <Enter> [44/44] foo.run false Watching for changes to 4 paths... (Enter to re-run, Ctrl-C to exit) ``` But `-w` alone fails: ```bash lihaoyi mill$ ./mill -i dev.run scratch -w foo.run [90/647] de.tobiasroeser.mill.vcs.version.VcsVersion.vcsState [647/647] dev.run [44/44] foo.run false Watching for changes to 4 paths... (Enter to re-run, Ctrl-C to exit) <Enter> .run(InputPumper.java:29) ... 1 more <Enter> Exception in thread "Thread-0" java.lang.RuntimeException: java.io.IOException: Read end dead at mill.main.client.InputPumper.run(InputPumper.java:34) at java.base/java.lang.Thread.run(Thread.java:834) Caused by: java.io.IOException: Read end dead at java.base/java.io.PipedInputStream.checkStateForReceive(PipedInputStream.java:262) at java.base/java.io.PipedInputStream.receive(PipedInputStream.java:226) at java.base/java.io.PipedOutputStream.write(PipedOutputStream.java:149) at mill.main.client.InputPumper.run(InputPumper.java:28) ... 1 more ``` With this PR, both versions succeed: ```bash lihaoyi mill$ ./mill -i dev.run scratch -i -w foo.run [90/647] de.tobiasroeser.mill.vcs.version.VcsVersion.vcsState [647/647] dev.run [44/44] foo.run false Watching for changes to 4 paths... (Enter to re-run, Ctrl-C to exit) <Enter> [44/44] foo.run false Watching for changes to 4 paths... (Enter to re-run, Ctrl-C to exit) <Enter> [44/44] foo.run false Watching for changes to 4 paths... (Enter to re-run, Ctrl-C to exit) ``` ```bash lihaoyi mill$ ./mill -i dev.run scratch -w foo.run [90/647] de.tobiasroeser.mill.vcs.version.VcsVersion.vcsState [647/647] dev.run [44/44] foo.run false Watching for changes to 4 paths... (Enter to re-run, Ctrl-C to exit) <Enter> [44/44] foo.run false Watching for changes to 4 paths... (Enter to re-run, Ctrl-C to exit) <Enter> [44/44] foo.run false Watching for changes to 4 paths... (Enter to re-run, Ctrl-C to exit) <Enter> [44/44] foo.run false Watching for changes to 4 paths... (Enter to re-run, Ctrl-C to exit) ```
- Loading branch information