Skip to content

Exiting a process calls exit() which isn’t thread-safe #83994

@DemiMarie

Description

@DemiMarie

On Unix-like platforms, std::process::exit calls libc::exit(). However, this can lead to undefined behavior in a multithreaded process.

In my case, this showed up as use-after-free crashes when running the testsuite for RPM Oxide. librpm registers an atexit() handler to clean up global resources, but this causes some of the resources to be freed while other threads are still using them. Other projects have had similar issues, such as the Rust bindings for RocksDB.

The best answer I know of is to call quick_exit instead, which only calls functions registered with at_quick_exit. Such functions should be safe to be called while other threads are running.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.disposition-closeThis PR / issue is in PFCP or FCP with a disposition to close it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions