| Home | Libraries | People | FAQ | More

## Theoretical async signal safety

In theory, walking the stack without decoding and demangling should be async signal safe.

In practice, it is not:

- Looks like a page fault while dumping the trace on a containerized/virtualized Windows system has a chance to deadlock. Page fault can happen easily as we have to write the dump either to memory or to a file.
- On POSIX systems a deadlock can happen if a signal is received when throwing an exception #131. Theoretically this can be worked around by bypassing the mutex locking in C++-runtime at exception throw (sample implementation in the 🐙 userver framework), or by using a very modern runtime (glibc-2.35+ with modern libgcc or modern LLVM's libunwind).
- `-fomit-frame-pointer` like flags add additional complexity to the stack walking implementation, which may also negatively affect the signal safety.

As a rule of thumb: do not capture stack traces in signal handlers unless you are absolutely sure in your environment and inspected all of its source codes.