runtime: Mono does not emit ProcessExit event on SIGTERM.

To reproduce:

dotnet new web -o web
cd web
dotnet run

Find the pid of the dotnet run process, and send it SIGTERM from another terminal:

kill -SIGTERM <pid>

With CoreCLR, the application shuts down, and the exit code is 0:

...
info: Microsoft.Hosting.Lifetime[0]
      Application is shutting down...
$ echo $?
0

With Mono, the application keeps running, the dotnet run process gets terminated:

Terminated
$ echo $?
143

The web process is still running, you can send it SIGTERM seperately and it terminates nicely.

info: Microsoft.Hosting.Lifetime[0]
      Application is shutting down...

This difference in behavior is causing one of the source-build smoke tests to fail: https://github.com/dotnet/source-build/issues/3174.

cc @akoeplinger

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Comments: 30 (29 by maintainers)

Commits related to this issue

Most upvoted comments

The HelloWorld process is exiting with the correct value:

neale     294347  294344 25 23:01 pts/0    00:00:02 dotnet run
neale     294366  294347  1 23:01 pts/0    00:00:00 /home/neale/HelloWorld/bin/Debug/net7.0/HelloWorld

$ kill -TERM 294347

An strace shows all the processes exiting with the desired value:

294366 +++ exited with 143 +++
294347 +++ exited with 143 +++

I changed the HelloWorld program to do:

System.Environment.ExitCode = 181;

And ran things again and this time looked at all the threads:

$ ps -u neale -wLf
neale     294552  294549  294552  4   16 23:18 pts/0    00:00:00 dotnet run
neale     294552  294549  294553  0   16 23:18 pts/0    00:00:00 dotnet run
neale     294552  294549  294554  0   16 23:18 pts/0    00:00:00 dotnet run
neale     294552  294549  294555  0   16 23:18 pts/0    00:00:00 dotnet run
neale     294552  294549  294556  0   16 23:18 pts/0    00:00:00 dotnet run
neale     294552  294549  294557  0   16 23:18 pts/0    00:00:00 dotnet run
neale     294552  294549  294558  0   16 23:18 pts/0    00:00:00 dotnet run
neale     294552  294549  294559  0   16 23:18 pts/0    00:00:00 dotnet run
neale     294552  294549  294562  0   16 23:18 pts/0    00:00:00 dotnet run
neale     294552  294549  294564  0   16 23:18 pts/0    00:00:00 dotnet run
neale     294552  294549  294565  6   16 23:18 pts/0    00:00:00 dotnet run
neale     294552  294549  294566  0   16 23:18 pts/0    00:00:00 dotnet run
neale     294552  294549  294567  0   16 23:18 pts/0    00:00:00 dotnet run
neale     294552  294549  294568  0   16 23:18 pts/0    00:00:00 dotnet run
neale     294552  294549  294569  2   16 23:18 pts/0    00:00:00 dotnet run
neale     294552  294549  294570  0   16 23:18 pts/0    00:00:00 dotnet run
neale     294571  294552  294571  0    5 23:18 pts/0    00:00:00 /home/neale/HelloWorld/bin/Debug/net7.0/HelloWorld
neale     294571  294552  294572  0    5 23:18 pts/0    00:00:00 /home/neale/HelloWorld/bin/Debug/net7.0/HelloWorld
neale     294571  294552  294573  0    5 23:18 pts/0    00:00:00 /home/neale/HelloWorld/bin/Debug/net7.0/HelloWorld
neale     294571  294552  294574  0    5 23:18 pts/0    00:00:00 /home/neale/HelloWorld/bin/Debug/net7.0/HelloWorld
neale     294571  294552  294575  0    5 23:18 pts/0    00:00:00 /home/neale/HelloWorld/bin/Debug/net7.0/HelloWorld
:
$ kill -TERM 294552
:
Hello, World!
..............................sigterm_signal_handler:300 - 294552 triggered
finalizer_thread:889 - 294552 fielded - ec: 0
sigterm_signal_handler:300 - 294571 triggered
finalizer_thread:889 - 294571 fielded - ec: 181
Process exit

The strace showed:

294574 exit_group(181)                  = ?
294574 +++ exited with 181 +++
294573 +++ exited with 181 +++
294572 +++ exited with 181 +++
294575 +++ exited with 181 +++
294571 +++ exited with 181 +++
294555 exit_group(143 <unfinished ...>
294555 <... exit_group resumed>)        = ?
294579 +++ exited with 143 +++
294570 +++ exited with 143 +++
294569 +++ exited with 143 +++
294567 +++ exited with 143 +++
294566 +++ exited with 143 +++
294565 +++ exited with 143 +++
294564 +++ exited with 143 +++
294562 +++ exited with 143 +++
294558 +++ exited with 143 +++
294557 +++ exited with 143 +++
294555 +++ exited with 143 +++
294554 +++ exited with 143 +++
294553 +++ exited with 143 +++
294552 +++ exited with 143 +++

So I think it’s doing what it should. Should I generate a PR?

It doesn’t address it for Windows. I am attempting to mimic the behaviour of coreCLR but haven’t had enough free cycles to get it done.