GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Windows: child_process.spawn leaving orphaned processes around when running processes in an sh shell · Issue #34830 · nodejs/node

Windows: child_process.spawn leaving orphaned processes around when running processes in an sh shell #34830

New issue
Copy link
New issue
Copy link
Closed
Closed
Windows: child_process.spawn leaving orphaned processes around when running processes in an sh shell#34830
Copy link
Labels
child_processIssues and PRs related to the child_process subsystem.windowsIssues and PRs related to the Windows platform.

Description

@ManiacDC
ManiacDC
opened on Aug 18, 2020
Issue body actions
  • Version: 12.14.1
  • Platform: Windows 10
  • Subsystem: x64 1909

What steps will reproduce the bug?

Please see this reproduction utility & its readme:
https://github.com/ManiacDC/npm-sh-issue

Basically, launching node from an sh shell, then running tsc from a new shell (sh -c) from within node, will leave orphaned processes behind when ctrl-c is hit in the terminal.

For reference, stdio is set to pipe, windowsHide is set to false, and shell is set to true. If stdio is set to 'inherit', this issue does not occur.

How often does it reproduce? Is there a required condition?

On demand. stdio must NOT be set to inherit. The shell launching node must be "sh" or "bash", the shell being used to launch tsc must be "sh" or "bash".

What is the expected behavior?

All child processes should close.

What do you see instead?

The child processes are orphaned and remain running until killed in the task manager (since they run tsc -w, which runs until terminated).

Additional information

This was originally discovered via lerna/lerna#2284 , reported on sindresorhus/execa#433, and narrowed down to this. I think this may actually be an issue with git-for-windows/msys2's implementation of sh & bash, but I'm not sure.

Reacted by Justin Chase, Sindre Sorhus, ehmicky, Mortifia, Sean Blonien, Josh Kellendonk, Florian Guitton, John Rosewicz, Ali Ashraf (OMO) and Daniel Santos

Activity

  1. bzoz commented on Aug 19, 2020

    @bzoz
    bzoz
    on Aug 19, 2020
    Contributor
    More actions

    It might be that npm waits for your pipes to be closed. You can try something like this we used to fix calling npm from CITGM: nodejs/citgm@595dcf6

    Anyway, there are a lot of moving parts here. It is possible that there is a Node bug here, or bash incorrectly sets up pipes or maybe npm is doing something off. Could you try to boil it down to something that at least does not include npm? A perfect reproducible example would only use your Node.js code, without npm and without tsc which also could introduce this.

    My guess is that when you do all this shell switcheroos npm ends up not using winpty (#14100 (comment)).

  2. ManiacDC commented on Aug 19, 2020

    @ManiacDC
    ManiacDC
    on Aug 19, 2020
    Author
    More actions

    Yes, it's not using winpty, but that's out of my control as this is being launched from a cross-platform shell script - which won't be using winpty. Also, how node launches the npm script is somewhat out of my control (this is being launched from within lerna in my original issue).

    The original example was a shell script launching lerna via npx to call npm scripts. I was able to get rid of the npx and lerna parts, but that's it.

    edit1:
    I figured out a way to remove npm from the picture - check the reproduction repo... tsc is still involved, but I'm just using that as a looping process and it exits normally in other situations.

    edit2:
    I also found a way to remove tsc. I added a second reproduction method using "sleep", instructions in readme. If sleep is launched directly from node, or even via "sh -c 'tsc -w'" from node - this issue does not happen. I had to launch it from within a script to get it to happen.

  3. ManiacDC
    changed the title [-]Windows: child_process.spawn leaving orphaned processes around when running npm scripts in an sh shell[/-] [+]Windows: child_process.spawn leaving orphaned processes around when running processes in an sh shell[/+] on Aug 19, 2020
  4. justinmchase commented on Aug 21, 2020

    @justinmchase
    justinmchase
    on Aug 21, 2020
    More actions

    I'm running in WSL and it has the same issue. The same code on osx behaves as expected.

  5. Leko
    added
    child_processIssues and PRs related to the child_process subsystem.
    windowsIssues and PRs related to the Windows platform.
    on Aug 29, 2020
  6. huseyinacacak-janea commented on May 2, 2024

    @huseyinacacak-janea
    huseyinacacak-janea
    on May 2, 2024
    Contributor
    More actions

    Hi @ManiacDC, I wanted to look into this issue but wasn't able to reproduce it (I tried Node 18.20.2, 20.12.2, and 22.0.0). Do you think this can be closed now?

  7. avivkeller commented on May 4, 2024

    @avivkeller
    avivkeller
    on May 4, 2024
    Member
    More actions

    @nodejs/child_process

  8. ManiacDC commented on May 5, 2024

    @ManiacDC
    ManiacDC
    on May 5, 2024
    Author
    More actions

    @huseyinacacak-janea I'm no longer developing in Node on Windows. If you can't reproduce, feel free to close, thanks!

  9. huseyinacacak-janea commented on May 8, 2024

    @huseyinacacak-janea
    huseyinacacak-janea
    on May 8, 2024
    Contributor
    More actions

    Node.js v12 has reached its end of life and I wasn't able to reproduce it with the latest versions.
    @redyetidev, @ManiacDC I don't have the right to close the issue. Can one of you please close it?

  10. targos
    closed this as completedon May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    child_processIssues and PRs related to the child_process subsystem.windowsIssues and PRs related to the Windows platform.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.