dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.85k stars 666 forks source link

Child processes are orphaned when stop debugging #4325

Open justinmchase opened 3 years ago

justinmchase commented 3 years ago

Issue Description

I have setup a launch json and when I press F5 it uses Process.Start to create some long running child procesess. If I detach the debugger my application process is killed, but the child processes are orphaned. These processes hold open fixed ports and simply pressing F5 a second time crashes the app since the ports are already open.

Steps to Reproduce

I can make a reproduction but its fairly complicated... But something like:

  1. Make a C# console app that shell exec's an app that opens a port:
    Process.Start("kubectl", "port-forward service/example 8080").WaitForExit();
  2. Create a standard launch.json and hit F5
  3. Shift+F5 (detach debugger)
  4. Press F5 again

Expected Behavior

The app successfully runs a second time and child processes are able to open their respective ports.

Actual Behavior

Child processes remain running and ports are locked.

Logs

[example] Unable to listen on port 8080: Listeners failed to create with the following errors: [unable to create listener: Error listen tcp4 127.0.0.1:8080: bind: address already in use unable to create listener: Error listen tcp6 [::1]:8080: bind: address already in use]
[example] error: unable to listen on any of the requested ports: [{8080 8080}]

OmniSharp log

N/A

C# log

N/A

Environment information

VSCode version: 1.52.0 C# Extension: 1.23.8

Mono Information OmniSharp using built-in mono
Dotnet Information .NET Core SDK (reflecting any global.json): Version: 3.1.404 Commit: 470f6754b3 Runtime Environment: OS Name: Mac OS X OS Version: 10.15 OS Platform: Darwin RID: osx.10.15-x64 Base Path: /usr/local/share/dotnet/sdk/3.1.404/ Host (useful for support): Version: 3.1.10 Commit: 1721e39439 .NET Core SDKs installed: 3.1.404 [/usr/local/share/dotnet/sdk] .NET Core runtimes installed: Microsoft.AspNetCore.App 3.1.10 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.10 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] To install additional .NET Core runtimes or SDKs: https://aka.ms/dotnet-download
Visual Studio Code Extensions |Extension|Author|Version| |---|---|---| |csharp|ms-dotnettools|1.23.8| |debugger-for-chrome|msjsdiag|4.12.11| |githistory|donjayamanne|0.6.14| |gitlens|eamodio|11.1.0| |insert-unicode|brunnerh|0.10.0| |prettify-json|mohsen1|0.0.3| |remote-containers|ms-vscode-remote|0.154.1| |vscode-docker|ms-azuretools|1.9.0| |vscode-nuget-package-manager|jmrog|1.1.6|;
gregg-miskelly commented 3 years ago

@PeterWone since you are so passionate about supporting gentile termination, I will go ahead and reopen #4553 and move your comments there. This work item will continue to be about terminating child processes when we terminate the root process.

PeterWone commented 3 years ago

@gregg-miskelly That's very kind of you.

I have cloned the code-base to look into the issues of implementing this. If you have any start-here pointers they would be welcome. For example, where to find the button handler code and some notes on how it's put together.

gregg-miskelly commented 3 years ago

@PeterWone I will follow up in the other issue.

justinmchase commented 2 years ago

I forgot I had previously created this issue and just went to bing and searched for "vscode stop debugging orphans processes" and found my own issue :)

I guess this is still an active issue.

SomeoneIsWorking commented 2 years ago

This happens for me but not related to OmniSharp because I run the programs from terminal tabs and when I close VSCode, they are still in the process list

kubuntu 21.10