-
Notifications
You must be signed in to change notification settings - Fork 29.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EPIPE
when writing to newly created child process's stdin
#40085
Comments
It should be noted that this code is already resulting in this error on |
In fact, this same behavior shows on |
Is this really bug? The |
Thanks @blattersturm and @santigimeno, I believe you are both correct. I tried reproducing my original problem and it now reproduces with much older Node.js versions as mentioned by @blattersturm. This seems to be a timing issue as pointed out by @santigimeno. For example, I have found that the following command works approximately half of the times on my machine (to reproduce, you need to adjust the size): spawn('bash', ['-c', 'echo ' + 'a'.repeat(57367)], { stdio: ['pipe', 'ignore', 'inherit'] }) However, even if the child process is in fact gone (which is most likely to be the case), the import { spawn } from 'child_process'
const childProcess = spawn('echo')
console.log('childProcess pid', childProcess.pid)
childProcess.on('spawn', () => {
console.log('childProcess spawn')
})
childProcess.on('exit', (exitCode, signal) => {
console.log('childProcess exit', exitCode, signal)
})
childProcess.on('close', (exitCode, signal) => {
console.log('childProcess close', exitCode, signal)
})
childProcess.on('error', (error) => {
console.log('childProcess error', error)
})
childProcess.stdin.on('error', (error) => {
console.log('stdin error', error)
})
console.log('stdin writable', childProcess.stdin.writable)
console.log('stdin writableEnded', childProcess.stdin.writableEnded)
console.log('stdin writableFinished', childProcess.stdin.writableFinished)
console.log('stdin destroyed', childProcess.stdin.destroyed)
console.log('before stdin write')
childProcess.stdin.write('test') Results in:
Are those attributes and events correct considering As a consequence, it becomes impossible to do the following safely: write to a child process's The best ways I can think of to solve this would be:
Is there a better way to do this? |
EPIPE
when writing to child process's stdin since Node 16.7.0
EPIPE
when writing to child process's stdin
EPIPE
when writing to child process's stdinEPIPE
when writing to newly created child process's stdin
Facing the same issue on
|
I'll go ahead and close this because I believe the consensus is that this isn't a bug (and I agree.) The child process object and the stdio streams emit various events that you can observe to know when it's safe to read and write. |
@bnoordhuis There is no flag or event which may be observed to write to stdin safely, see discussion at #48786 TL;DR see the comment #48786 (comment) |
But we don't have any way to do that when we use the |
Version
16.7.0 (changelog)
Platform
Linux ether-laptop 5.11.0-34-generic #36-Ubuntu SMP Thu Aug 26 19:22:09 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
Subsystem
child_process
What steps will reproduce the bug?
How often does it reproduce? Is there a required condition?
With Node
<=16.6.0
, this creates no error.Also, this only produces an error with specific binaries.
echo
does produce the error, butcat
ornode --version
do not.Finally, this seems to happen on macOS and Linux, but not on Windows.
What is the expected behavior?
No error should be produced.
Also,
test
should be written to the child process'sstdin
. Some modules like Execa rely on being able to pass a string or buffer to a child process's stdin (upstream issue for Execa: sindresorhus/execa#474).What do you see instead?
With Node
>=16.7.0
, this produces:The text was updated successfully, but these errors were encountered: