Best practices for clean-up after segfault / custom signal handler #848
-
We have some peripheral clean-up that we need to do before the application is closed down. This should be done even if there is e.g. a SEGFAULT. We do this currently by adding a signal handler for SEGFAULT that sets an error flag, we then do clean-up and exits the application. When using sentry-native it seems like the library is overriding our signal handlers to be able to send telemetry messages to sentry on SEGFAULTs. This handler seems to exit the application when done, meaning that we can't do our cleanup. We could manually override the sentry signal handler, but then we don't get the telemetry messages. Do we need to manually implement the transmission of a stacktrace to using sentry from our own signal handler, or is there a way we can get sentry to remove it's handler and raise the same (or another) signal after sending the stacktrace? Or is there any better way to design the error handling to achieve both clean-up and telemetry? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Hi, @daniel-falk! If you are asking for a solution specifically when a crash occurs, the preferred method would be to implement your shutdown by using our Here is the link to the docs: https://docs.sentry.io/platforms/native/configuration/filtering/#using-on_crash sentry-native/include/sentry.h Lines 831 to 875 in 6c76f58 |
Beta Was this translation helpful? Give feedback.
Hi, @daniel-falk! If you are asking for a solution specifically when a crash occurs, the preferred method would be to implement your shutdown by using our
on_crash
-hook which will be called from the crash handler before the crash snapshot is generated (not only forSIGSEGV
but all hard-exceptions).Here is the link to the docs: https://docs.sentry.io/platforms/native/configuration/filtering/#using-on_crash
And a bit more detailed in the header docs:
sentry-native/include/sentry.h
Lines 831 to 875 in 6c76f58