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 *still* don't quit after stopping debugging #38897

Closed
casperOne opened this issue Dec 8, 2021 · 15 comments
Closed

Node.js processes *still* don't quit after stopping debugging #38897

casperOne opened this issue Dec 8, 2021 · 15 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

Comments

@casperOne
Copy link

casperOne commented Dec 8, 2021

Describe the bug

The same issue as #5204, many nodejs instances continue to run after debugging an ASP.NET Core application.

Currently, I am using taskkill.exe /F /IM node.exe /T to shut down instances after each debugging session to mitigate this. Here's a screenshot showing 18 nodejs processes running (all children of VS.NET) after debugging:

image

One (or more) of these is typically (but not always) consuming a large amount of CPU.

It tends to slow down performance on my machine quite a bit after this.

To Reproduce

This is an ASP.NET Core React SPA application that was created with the template ~ASP.NET Core 2.1. It's been upgraded over time and is currently on ASP.NET Core 5.0.

Debugging occurs in VS.NET 2022.

I do have a private github repo that I'm willing to share privately to assist.

@TanayParikh TanayParikh added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Dec 8, 2021
@TanayParikh
Copy link
Contributor

Hello @casperOne, thanks for contacting us. Are you still experiencing this issue in .NET 6?

@TanayParikh TanayParikh added the Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. label Dec 8, 2021
@ghost
Copy link

ghost commented Dec 8, 2021

Hi @casperOne. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@casperOne
Copy link
Author

@TanayParikh Yes, after switching to 6.0, after going through two debug sessions, there were 13 nodejs processes that were hanging around.

image

@ghost ghost added Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. and removed Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. labels Dec 8, 2021
@TanayParikh
Copy link
Contributor

Hmm that's certainly strange. We've had issues with processes not being killed after debugging, but having 13 errant processes after just 2 debug session seems very odd.

Are you sure the processes are all being created by .NET / VS? Could you try using Proc Explorer to get an idea of the process hierarchy / tree?

@TanayParikh TanayParikh added Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. and removed Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. labels Dec 8, 2021
@ghost
Copy link

ghost commented Dec 8, 2021

Hi @casperOne. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@casperOne
Copy link
Author

@TanayParikh I've looked into this more. While debugging, the process tree looks like this:

image

You can see that the node instances are children of iisexpress. The full command line of the cmd.exe process that controls the nodejs process is

"cmd" /c npm run start -- 

However, when I close the browser (effectively ending the debugging session), the cmd.exe (with the child nodejs processes) gets orphaned:

image

@ghost ghost added Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. and removed Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. labels Dec 8, 2021
@TanayParikh
Copy link
Contributor

Thanks @casperOne that's really helpful. Do you have a minimal, public, GitHub repro project that we could use to investigate further? Note we aren't able to use private repos

@TanayParikh TanayParikh removed the Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. label Dec 8, 2021
@TanayParikh
Copy link
Contributor

Linking in #34425 and the associated PR: #34427.

@TanayParikh TanayParikh added the bug This issue describes a behavior which is not expected - a bug. label Dec 8, 2021
@casperOne
Copy link
Author

@TanayParikh I will try and whittle this down to something I can post on a public repo.

@mkArtakMSFT mkArtakMSFT added this to the .NET 7 Planning milestone Dec 8, 2021
@ghost
Copy link

ghost commented Dec 8, 2021

Thanks for contacting us.

We're moving this issue to the .NET 7 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@mkArtakMSFT
Copy link
Member

Thanks for contacting us. @javiercn can you please look into this when you're back from vacation and see what's the culprit here? Thanks!

@casperOne
Copy link
Author

casperOne commented Dec 8, 2021

@mkArtakMSFT @javiercn @TanayParikh I have a minimal example here

https://github.com/casperOne/asp-net-core-react-spa-note-wont-shut-down

It's my project, reduced to bare bones that sets up the ASP.NET Core side, displaying "Hello there" through React.

I've confirmed that the behavior with orphaned nodejs processes occurs with this example.

Note: You'll have to run yarn install in the ClientApp directory to initialize the node_modules directory before debugging.

@Smoovsky
Copy link

Same here.

I personally run a script every time after I'm done with debugging to get around with this.

# powershell script
get-process | where {$_.Name -eq 'node'}| foreach {$_.Kill()}

or with AutoHotKey(ctrl + k, ctrl + n)

#k::
    Input, OutputVar, L1

    If (Asc(OutputVar) = Asc("n"))
    {
        If(FileExist("C:\Program Files\PowerShell\7\pwsh.exe"))
        {
            Run "C:\Program Files\PowerShell\7\pwsh.exe" -Command "get-process | where {$_.Name -eq 'node'} | foreach {$_.Kill()}"
        }
    }

    Return

It will simply kill all node processes. You can also make it part of the debug flow(add it to .csproj or launch.json), but it's not recommended.

@casperOne
Copy link
Author

@Smoovsky

I personally run a script every time after I'm done with debugging to get around with this.

Yes, this (or some variation of this) can be done, the big problem is that it will kill other node processes that are running that are not involved with asp.net development.

While this would apply to my case, I see this as a "break in case of emergency" solution that shouldn't be the common approach in this scenario (even if it is currently the only approach that works).

@mkArtakMSFT
Copy link
Member

Thanks for the repro project, @casperOne.
We believe this has been addressed in .NET 6.

Also note, that .NET 5 is out of support.

@dotnet dotnet locked as resolved and limited conversation to collaborators Sep 9, 2022
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

5 participants