mono / mono

Mono open source ECMA CLI, C# and .NET implementation.
https://www.mono-project.com
Other
11.14k stars 3.82k forks source link

[Question]Causing intentional crashes? #17877

Open Tampa opened 4 years ago

Tampa commented 4 years ago

I am trying to debug the states a mono app may find itself in to detect whether or not it is stuck. Even running as deamon I have seen it stack trace, but not quit the process itself. Is there a reliable way to cause any mono app to stack trace and remain "running" so I can test these cases?

lambdageek commented 4 years ago

Not sure what you're asking - could you show an example of a stack trace that you're talking about? Ideally code and sample output.

In general, when mono receives a SIGQUIT, it will dump the stack traces for all threads and then continue running. Are you or something on your system sending signals to Mono?

using System;
using System.Threading;

public class P {
    public static void Main () {
        while (true) {
            Console.WriteLine ("ping");
            Thread.Sleep (1000);
        }
    }
}
$ mono foo.exe & sleep 5 ; kill -QUIT %1 ; sleep 2 ; kill %2
mono foo.exe & sleep 5 ; kill -QUIT %1
[1] 15021
ping
ping
ping
ping
ping
Full thread dump:

"<unnamed thread>"  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) System.Threading.Thread.SleepInternal (int) [0x00000] in <395c4032c0c340239e2399435b78ead2>:0
  at System.Threading.Thread.Sleep (int) [0x00019] in <395c4032c0c340239e2399435b78ead2>:0
  at P.Main () [0x0000f] in <f3d302b40fac485a84e8cf38403898e4>:0
  at (wrapper runtime-invoke) object.runtime_invoke_void (object,intptr,intptr,intptr) [0x0002a] in <395c4032c0c340239e2399435b78ead2>:0

"Finalizer"ping
ping
[1]+  Terminated: 15          mono foo.exe
Tampa commented 4 years ago

I am looking for something like a seg fault stack trace or similar, not that it continues running, but actually gets stuck and stops running. The application in question listens to xml data so when it is running sending xml headers returns no error code via curl, but when it gets stuck it will fail to return. The app runs on mono inside a screen session, when it shuts down the screen session terminates, but in some cases the app will fail catastrophically, stack trace and then just sit there not reacting to anything but sigterm. This stuck condition is what I am trying to get so I can develop tests to determine if the app is in that state and act accordingly to resolve the problem.

I already have something that seems to work and return proper codes when the app is stuck or it takes too long to respond, however I want to make sure that potential error states are covered so if I can make the app or mono fail in a manner that both terminates the application yet keeps the screen session alive that would be great.