Skip to content

std: don't clean up the main thread's altstack - #161037

Open
joboet wants to merge 1 commit into
rust-lang:mainfrom
joboet:main_altstack
Open

std: don't clean up the main thread's altstack#161037
joboet wants to merge 1 commit into
rust-lang:mainfrom
joboet:main_altstack

Conversation

@joboet

@joboet joboet commented Aug 13, 2026

Copy link
Copy Markdown
Member

Fixes #161018

#28069 added a call to what is now rt::cleanup to process::exit. rt::cleanup in turn calls the UNIX stack_overflow::cleanup, which frees the main thread's signal stack and uninstalls the current thread's signal handler in the assumption that the current thread is the main one – even though process::exit can be called from any thread.

This PR removes the main thread cleanup logic altogether, since, as the FIXME in stack_overflow::cleanup points out, it causes more issues than it is worth. This also means that stack overflows in TLS destructors will be caught on the main thread, partly addressing #111272.

@rustbot rustbot added O-unix Operating system: Unix-like O-windows Operating system: Windows S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Aug 13, 2026
@rustbot

rustbot commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

r? @clarfonthey

rustbot has assigned @clarfonthey.
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: @ChrisDenton, libs
  • @ChrisDenton, libs expanded to 13 candidates
  • Random selection from JohnTitor, Mark-Simulacrum, clarfonthey, nia-e

Comment on lines +146 to +151
// Store a pointer to the allocation for the main thread's altstack so that
// tools like valgrind don't complain about a leaked unreachable allocation.
//
// If the main thread exits, the process will terminate so there's no use in
// freeing resources. It also means that the altstack is still installed
// while TLS destructors are run on the main thread (c.f. #111272).

@clarfonthey clarfonthey Aug 13, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit: since we can generate private docs these should probably just be doc comments.

View changes since the review

@clarfonthey

Copy link
Copy Markdown
Contributor

Agree with the discussion that this is probably a lot more headaches than it's worth, although I think it's probably worth verifying that we've fixed the issues with flushing output on exit. It looks like that code has been since relocated, but I'm not 100% sure just looking at it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

O-unix Operating system: Unix-like O-windows Operating system: Windows S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. 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.

process::exit in a child thread unmaps the main thread's sigalt stack

3 participants