Skip to content

Commit 91afd1a

Browse files
jpnurmiclaude
andcommitted
fix: skip SA_NODEFER when CHAIN_AT_START is active
SA_NODEFER (added in #1446) is incompatible with the CHAIN_AT_START signal handler strategy. When chaining to the runtime's signal handler (e.g. Mono), the runtime may reset the signal to SIG_DFL and re-raise. With SA_NODEFER the re-raised signal is delivered immediately, killing the process before our handler can regain control. Without SA_NODEFER, the re-raised signal is blocked during handler execution, allowing the runtime handler to return and sentry-native to proceed with crash capture. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent ff71131 commit 91afd1a

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/backends/sentry_backend_inproc.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,16 @@ startup_inproc_backend(
507507
// running. This is needed for recursive crash detection to work -
508508
// without it, a crash during crash handling would block the signal
509509
// and leave the process in an undefined state.
510-
g_sigaction.sa_flags = SA_SIGINFO | SA_ONSTACK | SA_NODEFER;
510+
// However, SA_NODEFER is incompatible with CHAIN_AT_START: when we
511+
// chain to the runtime's signal handler (e.g. Mono), it may reset
512+
// the signal to SIG_DFL and re-raise. With SA_NODEFER the re-raised
513+
// signal is delivered immediately (killing the process) before our
514+
// handler can regain control.
515+
g_sigaction.sa_flags = SA_SIGINFO | SA_ONSTACK;
516+
if (g_backend_config.handler_strategy
517+
!= SENTRY_HANDLER_STRATEGY_CHAIN_AT_START) {
518+
g_sigaction.sa_flags |= SA_NODEFER;
519+
}
511520
for (size_t i = 0; i < SIGNAL_COUNT; ++i) {
512521
sigaction(SIGNAL_DEFINITIONS[i].signum, &g_sigaction, NULL);
513522
}

0 commit comments

Comments
 (0)