Skip to content

Commit

Permalink
task: illumos/Solaris have thread-local weirdness
Browse files Browse the repository at this point in the history
## Motivation

In `tokio::task::local`, there's a
`LocalState::assert_called_from_owner_thread` function, which checks
that the caller's thread ID matches that of the thread on which the
`LocalSet` was created. This assertion is disabled on FreeBSD and
OpenBSD, with a comment indicating that this is because those systems
have "some weirdness around thread-local destruction". If memory serves,
I believe the "weirdness" was related to the order in which
thread-locals are destroyed relative to each other, or something along
those lines.

Upon running the tests on illumos, there appears to be [a similar
panic][1] in the `task_local_set_in_thread_local` due to this assertion
assertion while dropping a `LocalSet` which lives in a thread-local.
This leads me to believe that illumos, and presumably Solaris, also
exhibit the same "weirdness". This wouldn't be too surprising, given the
shared heritage of those systems.

## Solution

This commit adds `target_os="illumos"` and `target_os="solaris"` to the
`cfg` attribute that disables the assertion on systems determined to
have weirdness. This fixes the test panicking on illumos.

In the future, it might be worthwhile to look into changign the
assertion to only be disabled on weirdness-having systems _while
dropping the `LocalSet`_, rather than all the time. That way, we can
still check other accesses. But, I wanted to make the minimum change
necessary to fix it here before messing around with that.

[1]: https://buildomat.eng.oxide.computer/wg/0/details/01J592RB0JR203RGGN0RYHJHMY/CHieo1Uee7qzRVyp811YBl0MvXGO3i0QA9ezPaFWj6hf6P3P/01J592RSWCNX1MCFYGW74AHVH6#S1954
  • Loading branch information
hawkw committed Aug 14, 2024
1 parent f18d6ed commit 347b921
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions tokio/src/task/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1160,9 +1160,14 @@ impl LocalState {

#[track_caller]
fn assert_called_from_owner_thread(&self) {
// FreeBSD has some weirdness around thread-local destruction.
// BSDs and Solarises has some weirdness around thread-local destruction.
// TODO: remove this hack when thread id is cleaned up
#[cfg(not(any(target_os = "openbsd", target_os = "freebsd")))]
#[cfg(not(any(
target_os = "openbsd",
target_os = "freebsd",
target_os = "illumos",
target_os = "solaris",
)))]
debug_assert!(
// if we couldn't get the thread ID because we're dropping the local
// data, skip the assertion --- the `Drop` impl is not going to be
Expand Down

0 comments on commit 347b921

Please sign in to comment.