Skip to content
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

spawn with stdio/stdin 'pipe' options causes pwsh shell to hang after execution #52364

Open
xadozuk opened this issue Apr 4, 2024 · 0 comments
Labels
child_process Issues and PRs related to the child_process subsystem.

Comments

@xadozuk
Copy link

xadozuk commented Apr 4, 2024

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
@VoltrexKeyva VoltrexKeyva added the child_process Issues and PRs related to the child_process subsystem. label Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
child_process Issues and PRs related to the child_process subsystem.
2 participants