Rust vs Signals: Why Vec and String Aren’t Signal-Safe

92 points FitWinner3340 46 comments

POSIX clearly states that malloc realloc and free are not async-signal-safe meaning they must not be called from signal handlers because they may use internal locks or inconsistent global state

Rust’s core dynamic containers such as Vec and String allocate memory through the global allocator which on most Unix systems ultimately calls malloc and free

If these allocation functions are not signal-safe why does Rust rely on them underneath Vec and String even though this means those types cannot be safely used in signal handlers?