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

Killing subprocess running run-script executor leaves orphaned processes #11782

Open
luxaritas opened this issue Aug 30, 2022 · 7 comments
Open
Assignees
Labels
scope: core core nx functionality type: bug

Comments

@luxaritas
Copy link
Contributor

Current Behavior

If runExecutor is called within a child process invoking the run-script executor, killing the child process (ie, before it has finished running) leaves the executed script running

Expected Behavior

The executed script should be signaled to exit

From my understanding, this is caused by run-script calling execSync - Node never cleans up child processes when it exists. Presumably, exec should be used instead, so that a handle to the child process can be retained, so that signal handlers installed on the current process can call kill when the current process exists, similarly to how run-commands works in parallel mode (that said - this issue is also presumably present in run-commands serial mode, which also uses execsync).

Steps to Reproduce

https://stackblitz.com/edit/node-k9o4py?file=main.js,proc.js - run npm start

Failure Logs

Environment

(This is for the stackblitz environment used for this repro above)

Node : 16.14.2
OS   : linux x64
npm  : 7.17.0
nx : 14.5.10
@nrwl/devkit : 14.5.10
@luxaritas
Copy link
Contributor Author

Worth noting that this also affects the task runner in general. ForkedProcessTaskRunner SIGTERMs its child processes when the current process receives SIGINT/SIGTERM/SIGHUP, but if one of those child processes is running run-script, the script being run won't be killed

@skrtheboss
Copy link
Contributor

It may be related to #11722

@FrozenPandaz FrozenPandaz added the scope: core core nx functionality label Sep 2, 2022
@diginikkari
Copy link
Contributor

I have probably hit the same issue with run-command executor. I'm trying to move some yarn scripts to own targets to related projects.
I created target for running firebase emulators using firebase cli firebase emulators:start . This starts few java -processes which are still running after terminating my target.

@chrisui
Copy link

chrisui commented Feb 20, 2023

This is also an issue with run-commands.

Ie. write an executor that spawns another nx run process. nx process runs a target defined with run-commands, spawning a persistant node server, kill the child nx process and the node process spawned by the run-commands will be orphaned and still live.

@purplecandy
Copy link

Do you have any updates on this issue? I'm having a lot of problems with the port still being used when the command is killed with Ctrl + C

Copy link

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
If we missed this issue please reply to keep it active.
Thanks for being a part of the Nx community! 🙏

@github-actions github-actions bot added the stale label Jan 13, 2024
@luxaritas
Copy link
Contributor Author

luxaritas commented Jan 13, 2024

I don't have the time to re-do the repro right now (and stackblitz is no longer playing nicely with nx) - any chance someone else on this thread can put together an updated repro for the latest nx version?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: core core nx functionality type: bug
Projects
None yet
Development

No branches or pull requests

7 participants