Skip to content

std: thread: Return error if setting thread stack size fails #144210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Gelbpunkt
Copy link
Contributor

Currently, when setting the thread stack size fails, it would be rounded up to the nearest multiple of the page size and the code asserts that the next call to pthread_attr_setstacksize succeeds.

This may be true for glibc, but it isn't true for musl, which not only enforces a minimum stack size, but also a maximum stack size of usize::MAX / 4 - PTHREAD_STACK_MIN 1, triggering the assert rather than erroring gracefully.

There isn't any way to handle this properly other than bailing out and letting the user know it didn't succeed.

@rustbot
Copy link
Collaborator

rustbot commented Jul 20, 2025

r? @ibraheemdev

rustbot has assigned @ibraheemdev.
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

@rustbot rustbot added O-unix Operating system: Unix-like 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 Jul 20, 2025
@Gelbpunkt
Copy link
Contributor Author

CI failure is unrelated and spurious, could you perhaps retry it?

@Gelbpunkt
Copy link
Contributor Author

Rebased to squash the fixup and re-trigger CI.

@Gelbpunkt
Copy link
Contributor Author

Two weeks passed, I guess I'll re-roll reviewers.

r? libs

@rustbot rustbot assigned jhpratt and unassigned ibraheemdev Aug 8, 2025
@jhpratt
Copy link
Member

jhpratt commented Aug 11, 2025

@bors r+

Tagging as release notes as this is something that may be worth calling out.

@bors
Copy link
Collaborator

bors commented Aug 11, 2025

📌 Commit e143986 has been approved by jhpratt

It is now in the queue for this repository.

@bors bors 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 Aug 11, 2025
@jhpratt jhpratt added relnotes Marks issues that should be documented in the release notes of the next release. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Aug 11, 2025
@jhpratt jhpratt 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 Aug 11, 2025
fmease added a commit to fmease/rust that referenced this pull request Aug 11, 2025
…r=jhpratt

std: thread: Return error if setting thread stack size fails

Currently, when setting the thread stack size fails, it would be rounded up to the nearest multiple of the page size and the code asserts that the next call to `pthread_attr_setstacksize` succeeds.

This may be true for glibc, but it isn't true for musl, which not only enforces a minimum stack size, but also a maximum stack size of `usize::MAX / 4 - PTHREAD_STACK_MIN` [1], triggering the assert rather than erroring gracefully.

There isn't any way to handle this properly other than bailing out and letting the user know it didn't succeed.

[1]: https://git.musl-libc.org/cgit/musl/tree/src/thread/pthread_attr_setstacksize.c#n5
fmease added a commit to fmease/rust that referenced this pull request Aug 12, 2025
…r=jhpratt

std: thread: Return error if setting thread stack size fails

Currently, when setting the thread stack size fails, it would be rounded up to the nearest multiple of the page size and the code asserts that the next call to `pthread_attr_setstacksize` succeeds.

This may be true for glibc, but it isn't true for musl, which not only enforces a minimum stack size, but also a maximum stack size of `usize::MAX / 4 - PTHREAD_STACK_MIN` [1], triggering the assert rather than erroring gracefully.

There isn't any way to handle this properly other than bailing out and letting the user know it didn't succeed.

[1]: https://git.musl-libc.org/cgit/musl/tree/src/thread/pthread_attr_setstacksize.c#n5
@fmease
Copy link
Member

fmease commented Aug 12, 2025

#145281 (comment)
@bors r-

@bors bors removed the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Aug 12, 2025
@rust-bors

This comment has been minimized.

@rust-bors
Copy link

rust-bors bot commented Aug 12, 2025

💔 Test for 63955d1 failed: CI. Failed jobs:

@rust-log-analyzer

This comment has been minimized.

@Zalathar
Copy link
Contributor

Failed in rollup: #145285 (comment)

@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Aug 12, 2025
@Zalathar
Copy link
Contributor

See also #145299, which aims to make the relevant test insensitive to thread scheduling.

@Gelbpunkt
Copy link
Contributor Author

I don't really see how that fail would be related at all, this PR only changes an assert to an error. The test doesn't rely on this assert, so I assume it was already broken before?

@Zalathar
Copy link
Contributor

I thought it might have been flaky too, but it failed twice in rollup, and then failed again with just this PR. 🤷‍♂️

I agree that the test is probably broken. Maybe this change is unlucky enough to perturb codegen in a way that happens to trigger the pre-existing problem.

@Zalathar
Copy link
Contributor

Might as well do another try job to see if we can catch the test being flaky instead of just failing:

@bors try jobs=x86_64-gnu-aux

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Aug 12, 2025
std: thread: Return error if setting thread stack size fails

try-job: x86_64-gnu-aux
@rust-log-analyzer

This comment has been minimized.

@rust-bors
Copy link

rust-bors bot commented Aug 12, 2025

💔 Test for 5266eb8 failed: CI. Failed jobs:

Copy link
Member

@joboet joboet left a comment

Choose a reason for hiding this comment

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

Wouldn't ErrorKind::InvalidInput be more correct?

@Zalathar
Copy link
Contributor

The failing test has been updated by #145299.

Currently, when setting the thread stack size fails, it would be rounded
up to the nearest multiple of the page size and the code asserts that
the next call to pthread_attr_setstacksize succeeds.

This may be true for glibc, but it isn't true for musl, which not only
enforces a minimum stack size, but also a maximum stack size of
usize::MAX / 4 - PTHREAD_STACK_MIN [1], triggering the assert rather
than erroring gracefully.

There isn't any way to handle this properly other than bailing out and
letting the user know it didn't succeed.

[1]: https://git.musl-libc.org/cgit/musl/tree/src/thread/pthread_attr_setstacksize.c#n5

Signed-off-by: Jens Reidel <[email protected]>
@Gelbpunkt Gelbpunkt force-pushed the thread-stack-size-musl branch from 25fe461 to 5d01d90 Compare August 14, 2025 18:37
@Gelbpunkt
Copy link
Contributor Author

Rebased to include the fix for the failing test and to address the feedback from @joboet

@Gelbpunkt
Copy link
Contributor Author

oops, forgot to:

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 14, 2025
@Zalathar
Copy link
Contributor

@bors try jobs=x86_64-gnu-aux

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Aug 15, 2025
std: thread: Return error if setting thread stack size fails

try-job: x86_64-gnu-aux
@rust-bors
Copy link

rust-bors bot commented Aug 15, 2025

☀️ Try build successful (CI)
Build commit: 10bc21a (10bc21a28ec076ae9982cca01a40120981e256bd, parent: 898aff704d6f0d00343f21d31b8b9bfac8e43007)

@jhpratt
Copy link
Member

jhpratt commented Aug 15, 2025

@bors r+

@bors
Copy link
Collaborator

bors commented Aug 15, 2025

📌 Commit 5d01d90 has been approved by jhpratt

It is now in the queue for this repository.

@bors bors 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 Aug 15, 2025
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 relnotes Marks issues that should be documented in the release notes of the next release. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

10 participants