Description
Version
v21.7.1
Platform
Linux *** 5.15.146.1-microsoft-standard-WSL2 #1 SMP Thu Jan 11 04:09:03 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
Subsystem
child_process
What steps will reproduce the bug?
To reproduce the issue, spawn pwsh with stdin configured with 'pipe':
const { spawn } = require('child_process')
const c = spawn('/opt/microsoft/powershell/7/pwsh', ['-c "Get-Date"'], { timeout: 1000, shell: true, stdio: ['pipe', 'pipe', 'pipe'] })
c.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
});
c.stderr.on('data', (data) => {
console.error(`stderr: ${data}`);
});
c.on('close', (code) => {
console.log(`child process exited with code ${code}`);
});
When ran, the pwsh is launched and hang. There is no data output on console and a strace show pwsh waiting on a futex.
Terminal output:
> node ./issue.js
stdout:
stdout: Thursday, 04 April 2024 10:39:56
(HANG)
After a kill of the pwsh process (through kill
command):
Terminal output:
child process exited with code null
How often does it reproduce? Is there a required condition?
Issue can be consistently reproduced when stdin is configured with pipe
.
What is the expected behavior? Why is that the expected behavior?
pwsh should exit after execution, but for some reason when stdin is configured with pipe
, the shell doesn't exit.
I cannot reproduce this issue outside of node (when launching pwsh from /bin/sh for example).
What do you see instead?
pwsh doesn't exit after the execution of the script.
It needs to be killed to trigger the close
callback.
Additional information
The issue doesn't appear if stdin is configured with inherit
.
In this case, pwsh close after executing the command as expected:
const { spawn } = require('child_process')
const c = spawn('/opt/microsoft/powershell/7/pwsh', ['-c "Get-Date"'], { timeout: 1000, shell: true, stdio: ['inherit', 'pipe', 'pipe'] })
c.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
});
c.stderr.on('data', (data) => {
console.error(`stderr: ${data}`);
});
c.on('close', (code) => {
console.log(`child process exited with code ${code}`);
});
Terminal output:
> node ./no-issue-inherit.js
stdout:
stdout: Thursday, 04 April 2024 10:26:46
child process exited with code null