Ctrl+C doesn't kill the dotnet.exe process when running an ASP.NET Core app interactively in docker
Install Docker
docker run -p 8000:80 -e "ASPNETCORE_URLS=http://+:80" -it --rm microsoft/dotnet
mkdir test
cd test
dotnet new mvc
dotnet restore
dotnet run
Ctrl+C
Output:
Hosting environment: Production
Content root path: /testweb
Now listening on: http://+:80
Application started. Press Ctrl+C to shut down.
^CApplication is shutting down...
root@27261394f459:/testweb# ps
PID TTY TIME CMD
1 ? 00:00:00 bash
119 ? 00:00:03 dotnet
147 ? 00:00:00 ps
If you then touch a file and try to dotnet build you will get errors that the app dll is locked by the dotnet.exe process.
As an alternative workaround to manually killing the dotnet process, you can run using the dotnet host instead of dotnet run - e.g. dotnet myApp.dll.
@davidfowl This is possibly related to msbuild or something else in the stack. @glennc has a repro even with a Console app.
@davidfowl did you get a chance to look into this?
No, not yet.
Workaround: Use Windows Powershell; CTRL-C will stop it.
This probably requires changes to dotnet itself. I'm betting Ctrl + C isn't being forwarded to the child process.
/cc @eerhardt
@davidfowl move to 2.1 for now?
I can reproduce it with dotnet core 2.0 preview on Fedora 26. This causes issue when trying to interact with the IDE (Eclipse IDE) as stopping the process created by the IDE doesn't stop the ASP.NET process. The result is that the user cannot easily control the process from the IDE, and worse, cannot easily run multiple time the project under development without going to console in order to kill the forked process.
What's stange also is that the forked process isn't killed when the child is killed. I would expect killing the dotnet run would cascade to killing the dotnet exec /path/to/project.dll
This probably requires changes to dotnet itself. I'm betting Ctrl + C isn't being forwarded to the child process.
@davidfowl Are you aware of a report about it on the dotnet side? I have the same impression that Ctrl+C isn't forwarded and/or that the chain of processes isn't correct.
dotnet doesn't forward Ctrl-C to child processes, so we won't be able to fix this in Hosting itself. Closing per the triage team's decision.
So shouldn't this issue be opened against dotnet directly? Is there an existing one we can already follow?
I'm curious: do you know whether most IDEs handle ASP.NET app properly then? How can the IDE user/C# developer doing ASP.NET app perform a run-modify-retry cycle if there is no way to stop the application under development from the host IDE/dotnet instance?
So shouldn't this issue be opened against dotnet directly? Is there an existing one we can already follow?
Yes, it should be.
I'm curious: do you know whether most IDEs handle ASP.NET app properly then? How can the IDE user/C# developer doing ASP.NET app perform a run-modify-retry cycle if there is no way to stop the application under development from the host IDE/dotnet instance?
None of the IDE's use dotnet run, they directly invoke the binary in the output folder via dotnet app.dll
IDE's? Or the command line? None of the IDE's use dotnet run, they directly invoke the binary in the output folder via dotnet app.dll
Ok, good to know.
FYI, we're working on the integration of dotnet (core) in Eclipse IDE, and
we've implemented the run operation with dotnet run. We'll investigate
more on this topic to evaluate which one should be preferred.
I've opened https://github.com/dotnet/cli/issues/7426
FYI, we're working on the integration of dotnet (core) in Eclipse IDE
Very cool! You should definitely directly run the process.
From the IDE, I believe 'dotnet run' is best and would like to stick to it. So I opened a ticket to dotnet CLI about having it forwarding the SIGTERM to subprocesses. Let's see how things move along.
-- Mickael Istria Eclipse IDE https://www.eclipse.org/downloads/eclipse-packages/ developer, at Red Hat Developers https://developers.redhat.com/ community
I don't see how it's best, like I said, none of the existing IDEs do it. For example, how would you get the existing pid to attach the debugger? Just another example of why running the process directly is better from an IDE.
Anyways good luck.
FWIW: I'm seeing this when using the Integrated Terminal in vscode too.