Hosting icon indicating copy to clipboard operation
Hosting copied to clipboard

Ctrl+C doesn't kill the dotnet.exe process when running an ASP.NET Core app interactively in docker

Open danroth27 opened this issue 9 years ago • 22 comments

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.

danroth27 avatar Mar 10 '17 17:03 danroth27

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.

MichaelSimons avatar Mar 14 '17 16:03 MichaelSimons

@davidfowl This is possibly related to msbuild or something else in the stack. @glennc has a repro even with a Console app.

muratg avatar Mar 20 '17 21:03 muratg

@davidfowl did you get a chance to look into this?

muratg avatar May 15 '17 16:05 muratg

No, not yet.

davidfowl avatar May 16 '17 02:05 davidfowl

Workaround: Use Windows Powershell; CTRL-C will stop it.

7100SW avatar May 18 '17 18:05 7100SW

This probably requires changes to dotnet itself. I'm betting Ctrl + C isn't being forwarded to the child process.

davidfowl avatar Jun 28 '17 14:06 davidfowl

/cc @eerhardt

davidfowl avatar Jun 28 '17 14:06 davidfowl

@davidfowl move to 2.1 for now?

muratg avatar Jun 28 '17 16:06 muratg

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

mickaelistria avatar Jul 28 '17 10:07 mickaelistria

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.

mickaelistria avatar Jul 28 '17 10:07 mickaelistria

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.

muratg avatar Aug 08 '17 19:08 muratg

So shouldn't this issue be opened against dotnet directly? Is there an existing one we can already follow?

mickaelistria avatar Aug 08 '17 22:08 mickaelistria

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?

mickaelistria avatar Aug 10 '17 17:08 mickaelistria

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

davidfowl avatar Aug 10 '17 17:08 davidfowl

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.

mickaelistria avatar Aug 10 '17 17:08 mickaelistria

I've opened https://github.com/dotnet/cli/issues/7426

mickaelistria avatar Aug 12 '17 10:08 mickaelistria

FYI, we're working on the integration of dotnet (core) in Eclipse IDE

Very cool! You should definitely directly run the process.

davidfowl avatar Aug 12 '17 18:08 davidfowl

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

mickaelistria avatar Aug 13 '17 08:08 mickaelistria

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.

davidfowl avatar Aug 13 '17 14:08 davidfowl

FWIW: I'm seeing this when using the Integrated Terminal in vscode too.

Kizmar avatar Nov 15 '17 14:11 Kizmar