Skip to content

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

Merged
bors merged 1 commit into
rust-lang:masterfrom
Gelbpunkt:thread-stack-size-musl
Aug 15, 2025
Merged

bors merged 1 commit into
rust-lang:masterfrom
Gelbpunkt:thread-stack-size-musl

Conversation

@Gelbpunkt

Copy link
Copy Markdown
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

rustbot commented Jul 20, 2025

Copy link
Copy Markdown
Collaborator

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
Comment thread library/std/src/sys/pal/unix/thread.rs Outdated
@Gelbpunkt

Copy link
Copy Markdown
Contributor Author

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

@Gelbpunkt

Copy link
Copy Markdown
Contributor Author

Rebased to squash the fixup and re-trigger CI.

@Gelbpunkt

Copy link
Copy Markdown
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

jhpratt commented Aug 11, 2025

Copy link
Copy Markdown
Member

@bors r+

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

@bors

bors commented Aug 11, 2025

Copy link
Copy Markdown
Collaborator

📌 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
Comment thread library/std/src/sys/pal/unix/thread.rs Outdated
@fmease

fmease commented Aug 12, 2025

Copy link
Copy Markdown
Member

#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 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

ghost commented Aug 12, 2025

Copy link
Copy Markdown
Contributor

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

ghost left a comment

Copy link
Copy Markdown
Member

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?

Comment thread library/std/src/sys/pal/unix/thread.rs Outdated
@Zalathar

ghost commented Aug 14, 2025

Copy link
Copy Markdown
Member

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 <adrian@travitia.xyz>
@Gelbpunkt
Gelbpunkt force-pushed the thread-stack-size-musl branch from 25fe461 to 5d01d90 Compare August 14, 2025 18:37
@Gelbpunkt

ghost commented Aug 14, 2025

Copy link
Copy Markdown
Contributor Author

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

@Gelbpunkt

ghost commented Aug 14, 2025

Copy link
Copy Markdown
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

ghost commented Aug 15, 2025

Copy link
Copy Markdown
Member

@bors try jobs=x86_64-gnu-aux

@rust-bors

This comment has been minimized.

@rust-bors

ghost commented Aug 15, 2025

Copy link
Copy Markdown
Contributor

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

@jhpratt

ghost commented Aug 15, 2025

Copy link
Copy Markdown
Member

@bors r+

@bors

ghost commented Aug 15, 2025

Copy link
Copy Markdown
Collaborator

📌 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
@bors
bors merged commit a676c48 into rust-lang:master Aug 15, 2025
@rustbot rustbot added this to the 1.91.0 milestone 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