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

19.8.1 leaves dangling child processes on Windows #28207

Closed
1 of 4 tasks
CreativeTechGuy opened this issue Sep 30, 2024 · 15 comments
Closed
1 of 4 tasks

19.8.1 leaves dangling child processes on Windows #28207

CreativeTechGuy opened this issue Sep 30, 2024 · 15 comments
Assignees
Labels
scope: core core nx functionality type: bug

Comments

@CreativeTechGuy
Copy link

Current Behavior

When pressing ctrl+c on windows to kill a NX command (eg: a dev server), it leaves all of the sub-processes (node, esbuild, vite, etc) running.

Expected Behavior

When pressing ctrl+c on windows to kill a NX command (eg: a dev server), it should kill all of the processes which were created.

GitHub Repo

No response

Steps to Reproduce

  1. Run a NX command which uses the nx:run-commands executor
  2. Kill the command in the terminal with ctrl+c
  3. Check Windows Task Manager to see that the process that was started is still running (this is easiest to see if the first process starts a server on a port since the second run will now fail since that port is still in-use)

Nx Report

Node           : 20.17.0
OS             : win32-x64
Native Target  : x86_64-windows
pnpm           : 9.11.0

nx                 : 19.8.1
@nx/js             : 19.8.1
@nx/jest           : 19.8.1
@nx/linter         : 19.8.1
@nx/eslint         : 19.8.1
@nx/workspace      : 19.8.1
@nx/devkit         : 19.8.1
@nx/esbuild        : 19.8.1
@nx/eslint-plugin  : 19.8.1
@nx/plugin         : 19.8.1
@nrwl/tao          : 19.8.1
@nx/vite           : 19.8.1
typescript         : 5.6.2

Failure Logs

N/A

Package Manager Version

No response

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

This is the commit which broke it: #28073

This is the NodeJS reference for why it's broken: nodejs/node#29837 (comment)

@BitBuf
Copy link

BitBuf commented Sep 30, 2024

Issue still present on 19.8.2, we've rolled back to 19.8.0 in the meantime.

@MaxKless
Copy link
Collaborator

There is some nuance to this. The sub-processes you see are probably the plugin workers. Nx spawns them when calculating the project graph and their lifecycle is tied to the parent process. By default, this parent process is the nx daemon. So as long as the daemon is running, the plugin workers will be running.

This is independent from the individual task execution and is expected behavior.

It's very possible that there is still an issue stemming from windowsHide: true. Can you set the NX_DAEMON env variable to false and recheck the behaviour? Now, all child processes should be stopped once task execution stops.

Is there a difference between tasks that end by themselves (like build, usually) and tasks that you kill manually (like serve in your example)?

@CreativeTechGuy
Copy link
Author

@MaxKless Thanks for the reply!

NX_DAEMON=false didn't make a difference unfortunately.

And yes it's only with tasks the user kills. A build type task won't have the same issue since the process ends and isn't killed.

I've confirmed that by doing a find/replace in all of the nx & @nx packages for windowsHide: true -> windowsHide: false that it fixes the issue. That was the only fix I was able to find.

@MaxKless
Copy link
Collaborator

yeah I can repro this and am working on a fix. I don't want to replace all instances of windowsHide: true since that will result in popups everywhere again. It might be okay to set it to false for executor invocations, though. I'm investigating.

@lppedd
Copy link

lppedd commented Oct 17, 2024

Anyone know in which version this issue was introduced? I'm currently on 19.6.6, and not sure to which version I'd have to update to avoid zombie processes.

@MaxKless
Copy link
Collaborator

If you wait just a couple of hours, you should be fine to update to 20.0.2

@CreativeTechGuy
Copy link
Author

@lppedd 19.8.0 doesn't have the issue, it was introduced in 19.8.1. And it seems like it's been fixed in 20.0.2! (Thanks @MaxKless)

@CreativeTechGuy
Copy link
Author

Looks like the PR to fix this is #28496 (just tagging to link the two).

@lppedd
Copy link

lppedd commented Oct 17, 2024

Thanks @MaxKless! @CreativeTechGuy do you see prompt windows popping up as a side effect?

@CreativeTechGuy
Copy link
Author

@lppedd The fixed version hasn't been released yet so I cannot test it. But when making the patch locally, yes a windows command prompt window will flash for a second and then close. Doesn't really bother me.

@MaxKless
Copy link
Collaborator

20.0.2 is out! So please try this new version and confirm that it's fixed.
I'll also release a new Nx Console version that fixes even more dangling process errors.

Please let me know if you run into any windows popups after the update, I didn't locally, but it might still happen. We will have to take care of those manually. Thank you :)

@lppedd
Copy link

lppedd commented Oct 18, 2024

@MaxKless upgraded to 20.0.2 and it behaves as expected for me. No popups currently, I'll keep you posted.

@mklueh
Copy link

mklueh commented Nov 16, 2024

I don't think this is entirely fixed yet. I have constant CMD popups still, and Node.exe processes running in the background while using 20.1.1

@MaxKless
Copy link
Collaborator

Node.exe processes running in the background are entirely normal, there's the daemon and plugin workers and the language server if using Nx Console.
Regarding the popups, that sucks. Could you create a new issue with more details?
If you can create a minimal repro using the same plugins you're using in your repository where you're seeing this, that's the easiest way to help us fix this! Just @ me in it and I'll look into it :)

@mklueh
Copy link

mklueh commented Nov 24, 2024

@MaxKless I know they are normal, but sometimes it feels like things are stuck in the background and taking up 1GB+ memory still. But I can't tell for sure if this is Nx related.

Regarding popups, I got one step further now.

It seems ,CMD is used through Windows Terminal, and then the Windows Terminal stays open without and CMD tab in it.

After adjusting the CMD settings from Automatic to

Image

the popups at least close afterwards and won't stay open.

I've created a reproducer, which is basically just a fresh workspace, the demo app duplicated and a few nx dependencies added, and my nx.json from my actual application.

https://github.com/mklueh/nx-popup-reproducer/tree/test

Running

yarn nx show projects --affected

will trigger the CMD popup.

Although it opens a popup, it doesn't do it every time I run the command, contrary to my real project.

Besides that I've found out that the vue-language-server is also leaving a cmd.exe popup open (or maybe the only process that leaves the popup open?). This is from the manual closing of the popup using https://learn.microsoft.com/en-us/sysinternals/downloads/procmon

Image

So after disabling the vue language service, I do not get popups that stay open anymore, only those that close right afterwards, independently from the terminal setting changes described above.

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