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 #616.
This adds some tests related to the race condition that happens when we redirect a child process's
stdin
/stdout
/stderr
right after spawning it.Since it's been just spawned, it might already have read/written from/to its standard streams, before we get a chance to pipe from/to them.
However, things work mostly correctly thanks to proper behavior from both the OS and the runtime, as described in the end of my comment here.
Unfortunately, there is one of those assumptions that does not seem to hold true. Namely, a process's
stdout
/stderr
might be lost if either:await childProcess
was called. This is most likely to happen for users that do not call that statement right away.stdout
/stderr
(when using thestdio: filePath | fileURL | WritableStream
option). This might happen if the child process is very fast. This includes when the child process fails very fast, although in that case the user gets the exit code at least, but might be missing some precious error logs.I am not sure there is something we can do about this. At the OS-level, the process spawning syscalls just sets up the standard streams. Reading/writing them must happen after spawning. And the process might have already exited. I do not think this is not specific to Node.js.