Skip to content

Fix observable intermediate state in thread::add_spawn_hook#159956

Open
maxdexh wants to merge 2 commits into
rust-lang:mainfrom
maxdexh:fix-thread-spawn-hook-159923
Open

Fix observable intermediate state in thread::add_spawn_hook#159956
maxdexh wants to merge 2 commits into
rust-lang:mainfrom
maxdexh:fix-thread-spawn-hook-159923

Conversation

@maxdexh

@maxdexh maxdexh commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Fixes #159923.

Ensures the intermediate state of there being no hooks in add_spawn_hooks is not observable by allocating the new head node before taking the current hook list.

Also added a note to the docs of add_spawn_hook that hooks are not guaranteed to run and cannot be relied upon for soundness, as there are multiple ways to prevent all/some hooks from running.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jul 26, 2026
@rustbot

rustbot commented Jul 26, 2026

Copy link
Copy Markdown
Collaborator

r? @folkertdev

rustbot has assigned @folkertdev.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 74 candidates
  • Random selection from 15 candidates

@maxdexh

maxdexh commented Jul 26, 2026

Copy link
Copy Markdown
Contributor Author
  • Owners of files modified in this PR: compiler

This doesn't touch the compiler?

@folkertdev

Copy link
Copy Markdown
Contributor

I guess all of the compiler is compiler? anyhow, I think you can also explicitly

r? libs

@maxdexh

maxdexh commented Jul 26, 2026

Copy link
Copy Markdown
Contributor Author

Thanks ^^
It's probably because I had to add the test in ui/std (at least it didn't work anywhere else, idk if I did something wrong), since it uses a custom global allocator.

@Mark-Simulacrum

Copy link
Copy Markdown
Member

@bors r+ rollup

@rust-bors

rust-bors Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

📌 Commit f80e5c1 has been approved by Mark-Simulacrum

It is now in the queue for this repository.

🌲 The tree is currently closed for pull requests below priority 100. This pull request will be tested once the tree is reopened.

Reason for tree closure: spurious failures

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Thread spawn hooks can be removed using unwinding handle_alloc_error

4 participants