dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.87k stars 674 forks source link

Node.js doesn't quit while stop debugging #2387

Closed chesteryang closed 6 years ago

chesteryang commented 6 years ago

Environment data

dotnet --info output: dotnet-info.txt

VS Code version:1.24.1 C# Extension version:1.15.2

The issue was filed to vscode first: https://github.com/Microsoft/vscode/issues/51933

Steps to reproduce

  1. create a new asp.net core react app. ( dotnet new ... ... )
  2. make it working.
  3. using default ".NET Core Launch (web)" to start debugging.
  4. Everytime starting debugging, after stop debugging, three or four more nodejs processes hanging in Task Manager. it quickly consumed all memory and make computer not responsive. nodejs

In process explorer this was found:

In debugging, process (id=13360) is a child process under dotnet.exe process (id=11188)

indebugging

Out of debugging, the process (id=13360) didn't get killed and its parent is gone. outofdebugging

Expected behavior

It should work like Visual Studio 2017's debugging, while stopping debugging, all nodejs processes should be killed.

Actual behavior

nodjs processes are hanging in memory.

gregg-miskelly commented 6 years ago

@chesteryang The debugger doesn't know anything about these node.js processes, so it will not kill them. This is true for both Visual Studio and VS Code.

Is your code spawning them?

chesteryang commented 6 years ago

@gregg-miskelly
Yes, the project was created using dotnet new reactredux -n my-app.

in Startup.cs,

        app.UseSpa(spa =>
        {
            spa.Options.SourcePath = "ClientApp";

            if (env.IsDevelopment())
            {
                spa.UseReactDevelopmentServer(npmScript: "start");
            }
        });

in package.json "scripts": { "start": "rimraf ./build && react-scripts start",

This script will create those nodejs processes. But in Visual Studio 2017, default to IIS express, stop debugging will kill all of them.

chesteryang commented 6 years ago

and in command line, if I use dotnet run to start app, I can use ctrl+c to shut down dotnet process and all its child processes.

gregg-miskelly commented 6 years ago

So you can get the command line behavior if you set "console": "externalTerminal". 'integratedTerminal' would probably also work.

For a better fix: if I am tracking things down correctly, it sounds like you are running into a bug in the ASP.NET JavaScriptServices. There is an issue that sounds just like you describe here: https://github.com/aspnet/JavaScriptServices/issues/270

Looking at what I think is their code to spawn node, they seem to be providing their parent pid for this purpose.

gregg-miskelly commented 6 years ago

Should have also said: so I would probably suggest opening a new issue in that repo if you are running a build that should have that fix.

chesteryang commented 6 years ago

@gregg-miskelly Okay, thanks.