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

Node.js processes don't quit after stopping debugging #5204

Closed
chesteryang opened this issue Jun 25, 2018 · 19 comments
Closed

Node.js processes don't quit after stopping debugging #5204

chesteryang opened this issue Jun 25, 2018 · 19 comments
Assignees
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates bug This issue describes a behavior which is not expected - a bug. feature-spa
Milestone

Comments

@chesteryang
Copy link

Please refer to dotnet/vscode-csharp#2387 for details.

If there has been a fix, let me know how.

@bharney
Copy link

bharney commented Jul 7, 2018

Until then I guess you can always kill the processes manually taskkill /f /im node.exe

@chesteryang
Copy link
Author

@bharney Thanks, I am using windows so I can use task manager to kill a process. Another workaround is to launch app in external command line window and after stopping debug, as this window is still on, I can use ctrl+c to terminate it.
But this is indeed a bug. If I use Visual Studio 2017, those node processes will be killed after stopping debug. Only Visual Studio Code failed to do so.

@remcoros
Copy link

remcoros commented Aug 8, 2018

It's not specific to just vscode and/or debugging.

I start my app using "dotnet run".

When closing that console (or hit Ctrl+C), the webserver stops running, but both the .NET process and node.exe process stay running as zombie processes:

image

@aspnet-hello aspnet-hello transferred this issue from aspnet/JavaScriptServices Dec 17, 2018
@aspnet-hello aspnet-hello added area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates feature-spa labels Dec 17, 2018
@mkArtakMSFT
Copy link
Member

Thanks for contacting us.
@SteveSandersonMS, is there anything we can do here?
Looks like the way we start the npm process already passes the parent process id, but for some reason it doesn't end, when the parent ends: https://github.com/aspnet/JavaScriptServices/blob/892d3c04202c67fc06fe89ff3580f6e99612b55b/src/Microsoft.AspNetCore.NodeServices/HostingModels/OutOfProcessNodeInstance.cs#L232

@SteveSandersonMS
Copy link
Member

SteveSandersonMS commented Jan 23, 2019

I agree it would be good if we could find a way to do this automatically. I don't know the correct way to launch child process such that they (and all transitive descendant processes) will die automatically if the root process dies, but if there is a way to do that, I expect we'd accept a PR to use that technique.

@pakrym
Copy link
Contributor

pakrym commented Jan 23, 2019

@loop-evgeny
Copy link

loop-evgeny commented Mar 13, 2019

This happens for me in VS 2017 Pro 15.9.9 and VS 2019 Preview 4.2. When I start an ASP.NET Core 2.1 or 2.2 React app from VS (with debugging) and stop debugging the node.exe processes remain. If I run outside of VS using dotnet run and kill that with Control+C the node.exe processes exit.

@mkArtakMSFT mkArtakMSFT added this to the 5.0.0 milestone Aug 13, 2019
@mkArtakMSFT mkArtakMSFT added the bug This issue describes a behavior which is not expected - a bug. label Aug 13, 2019
@mkArtakMSFT mkArtakMSFT modified the milestones: 5.0.0, 5.0.0-preview1 Aug 30, 2019
@ChristopherHaws
Copy link
Contributor

ChristopherHaws commented Oct 1, 2019

This also occurs when running in IIS Express without debugging and changing C# code so the process restarts automatically. I find myself going into task manager multiple times per day and cleaning up 10s of orphaned processes. Is there no way this can be patched in 3.1? It is quite annoying to deal with all day, every day. Thanks!

@astashko
Copy link

astashko commented Nov 25, 2019

It seems like Microsoft.AspNetCore.SpaServices.Extensions doesn't specify parent process id:
https://github.com/aspnet/AspNetCore/blob/9e67b7b22e92f3f4550d0efc2737d072405f0190/src/Middleware/SpaServices.Extensions/src/Npm/NodeScriptRunner.cs#L44-L56
Is it planned to be resolved?

@Patrick-Ullrich
Copy link

Can confirm, having this issue with:
DotNetCore v3.1.100
Visual Studio 2019 v.16.4.0

if (env.EnvironmentName == "Development") { spa.UseReactDevelopmentServer(npmScript: "start"); }

@Hecatron
Copy link

I ran across this bug recently after looking at the below announcement
since UseWebpackDevMiddleware is going away

Testing

after a bit of testing it looks like this cropped up sometime between version 2.2 and 3.0

  • .net core 2.1 / extensions - 2.1.1 okay
  • .net core 2.2 / extensions - 2.2.0 okay
  • .net core 3.0 / extensions - 3.0.0 broken
  • .net core 3.1 / extensions - 3.1.0 broken

Something about the way it's opening the process is leaving the process open after the debug session closes / visual studio quits.

For testing I found a repo online that was already setup to use UseReactDevelopmentServer
This works / doesn't leave anything behind in memory by default since it's targeting .net core 2.1

git clone https://github.com/ElHavas666/test-fianl.git
cd test-fianl
npm install

webpack / vue equivilent

I've been looking at creating a webpack equivalent since that's what I'm interested in but it looks like the webpack dev server has the same issue if I copy / paste the code from

There's also been one or two Vue dev server implementations floating around on the web that have run into the same problem.

Cause

I'm not sure of the cause but there's some suggestion that running stuff via "npm start" might not be such as good idea if it's not passing on SIGKILL, SIGTERM and SIGINT

another approach might be to use npx instead to launch the dev server which might be more direct / better so I'll be trying that next in my own implementation for webpack.

These are some other links I came across the top one lists a possible better way which involves proxying via the dev server first then the asp .net host second, although I haven't looked into that yet.

@Hecatron
Copy link

hmm so I just ruled out npm as the issue
launching the following within NodeScriptRunner

cmd /c echo hello

leaves nothing open after quitting as that's not a loop / terminates by iteself
launching this which is a simple ping on an infinite loop

cmd /c ping -t 127.0.0.1

keeps the cmd open after stopping debugging / quitting studio so same issue / never terminates
also tried adding in

AppDomain.CurrentDomain.DomainUnload += (s, e) => { process.Kill(true); process.WaitForExit(); };
AppDomain.CurrentDomain.ProcessExit += (s, e) => { process.Kill(true); process.WaitForExit(); };
AppDomain.CurrentDomain.UnhandledException += (s, e) => { process.Kill(true); process.WaitForExit(); };

but that didn't do anything / stop it so it must be further up

@mkArtakMSFT
Copy link
Member

Related #11597

@superlazycoder
Copy link

Annoying......

I created a bat file

kill-node.bat
taskkill /f /im node.exe

and added a postbuild event

call kill-node.bat

set to run post build event "Always"

Ill be left with a lingering node between builds, but a pretty good middle ground.

@ryanbrandenburg
Copy link
Contributor

This was resolved with #11597.

@Hecatron
Copy link

Hecatron commented Feb 1, 2020

I'm not sure if this has fixed it, I tried copying the contents of

Npm/
Util/
ReactDevelopmentServer/

https://github.com/dotnet/aspnetcore/tree/master/src/Middleware/SpaServices.Extensions/src

into my own class library to see if the applicationStoppingToken stuff which had been added in was working
but it seems to have the same problem when testing against the default react template with stuff being left open in the background
Maybe this has been tested against newer VStudio code or updated code in other libs, so will need to wait for it to be released officially to see

Edit
The cancellation token isn't being triggered when the browser closes / everything stops

var applicationStoppingToken = appBuilder.ApplicationServices.GetRequiredService<IHostApplicationLifetime>().ApplicationStopping;

Hopefully this has been fixed somewhere down the line in the latest master

@Hecatron
Copy link

Hecatron commented Feb 2, 2020

Update it looks like this does work as long as you don't use IISExpress while debugging
with IISExpress selected I think it runs into this old problem
aspnet/AspNetCoreModule#38

Avoiding IISExpress shouldn't be an issue so cool beans

@drdamour
Copy link

drdamour commented Feb 5, 2020

@ryanbrandenburg any chance this makes it into a 3.x release?

@mkArtakMSFT
Copy link
Member

@ryanbrandenburg any chance this makes it into a 3.x release?

@drdamour we won't be patching 3.x for this.

@ghost ghost locked as resolved and limited conversation to collaborators Mar 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates bug This issue describes a behavior which is not expected - a bug. feature-spa
Projects
None yet
Development

No branches or pull requests