Skip to content

thread::park causes undefined behaviour on panic #102398

Closed
@joboet

Description

@joboet

A lot of code dealing with synchronization assumes that thread::park does not panic. This assumption is however not correct. For instance, a panic occurs if the TLS key used to store the thread info cannot be created, if a new thread id cannot be created, if the creation of a parking primitive fails, if the current time is not available and if the parking operation fails.

The code examples above all use intrusive lists and have to wait on a condition to before destroying the list nodes. If thread::park panics, the nodes will be dropped during stack unwinding without checking that condition, leading to undefined behaviour (some of these cases are in std, so I'm marking this as a soundness problem with std).

Fixing this would either require guarding against panics in each of these cases or ensuring that thread::park never panics.

@rustbot label +I-unsound +A-atomic +T-libs +T-libs-api

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-atomicArea: Atomics, barriers, and sync primitivesI-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-mediumMedium priorityT-libsRelevant to the library team, which will review and decide on the PR/issue.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions