dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
34.91k stars 9.86k forks source link

SPA server doesn't stop when debugging in VS Code is stopped #50841

Open ontanj opened 10 months ago

ontanj commented 10 months ago

Is there an existing issue for this?

Describe the bug

When stopping a ASP.NET Core SPA application after debugging it in VS Code, the SPA server isn't stopped but continues to run in the background.

Expected Behavior

The SPA should be stopped just like the backend server.

Steps To Reproduce

  1. Create app from template:
    $ mkdir spa-test
    $ cd spa-test
    $ dotnet new react 
    $ cd ClientApp
    $ npm install
    $ code ..
  2. .vscode/launch.json:
    {
    "version": "0.2.0",
    "configurations": [
    {
      // Use IntelliSense to find out which attributes exist for C# debugging
      // Use hover for the description of the existing attributes
      // For further information visit https://github.com/dotnet/vscode-csharp/blob/main/debugger-launchjson.md.
      "name": ".NET Core Launch (web)",
      "type": "coreclr",
      "request": "launch",
      "preLaunchTask": "build",
      // If you have changed target frameworks, make sure to update the program path.
      "program": "${workspaceFolder}/bin/Debug/net6.0/spa-test.dll",
      "args": [],
      "cwd": "${workspaceFolder}",
      "stopAtEntry": false,
      // Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
      "serverReadyAction": {
        "action": "openExternally",
        "pattern": "\\bNow listening on:\\s+(https?://\\S+)"
      },
      "env": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "sourceFileMap": {
        "/Views": "${workspaceFolder}/Views"
      }
    }
    ]
    }
  3. .vscode/tasks.json:
    {
    "version": "2.0.0",
    "tasks": [
    {
      "label": "build",
      "command": "dotnet",
      "type": "process",
      "args": [
        "build",
        "${workspaceFolder}/spa-test.sln",
        "/property:GenerateFullPaths=true",
        "/consoleloggerparameters:NoSummary"
      ],
      "problemMatcher": "$msCompile"
    }
    ]
    }
  4. Start debugging.
  5. Stop debugging.

To verify that the SPA server is still running, you can try to start it manually and it will complain that the port is in use.

$ npm start

Exceptions (if any)

No response

.NET Version

6.0.120

Anything else?

.NET SDK (reflecting any global.json):
 Version:   6.0.120
 Commit:    d63b17be66

Runtime Environment:
 OS Name:     fedora
 OS Version:  38
 OS Platform: Linux
 RID:         fedora.38-x64
 Base Path:   /usr/lib64/dotnet/sdk/6.0.120/

global.json file:
  Not found

Host:
  Version:      6.0.20
  Architecture: x64
  Commit:       a08d9ce2ca

.NET SDKs installed:
  6.0.120 [/usr/lib64/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.20 [/usr/lib64/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.20 [/usr/lib64/dotnet/shared/Microsoft.NETCore.App]

Download .NET:
  https://aka.ms/dotnet-download

Learn about .NET Runtimes and SDKs:
  https://aka.ms/dotnet/runtimes-sdk-info

Process hierarchy while debug is running:

$ pstree -s 47853
systemd───systemd───code───code───vsdbg-ui───dotnet───npm start───node───node───10*[{node}]

Process hierarchy after debugging has stopped:

$ pstree -s 47853
systemd───systemd───npm start───node───node───10*[{node}]

When running the application with dotnet run the SPA server stops immediately.

javiercn commented 10 months ago

@ontanj thanks for contacting us.

That's by design, the spa server only gets automatically stopped when the .NET app launches it. If you start it manually, then it is expected that we don't stop it and you do so too manually.

ontanj commented 10 months ago

In this case I am not starting it manually. The VS Code debugger is starting the .NET app which launches the SPA. After stopping the .NET application the SPA process is still running but since I did not start it manually my only option to stop it is to find the right process through the system monitor and kill it. Sorry if that was unclear in any way.

ontanj commented 10 months ago

@javiercn

ontanj commented 10 months ago

@javiercn can you please take a look at this again as your reply doesn't apply to this case?