Skip to content
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

Truncate thread names on Linux and Apple targets #103379

Merged
merged 3 commits into from Oct 25, 2022

Conversation

cuviper
Copy link
Member

@cuviper cuviper commented Oct 22, 2022

These targets have system limits on the thread names, 16 and 64 bytes
respectively, and pthread_setname_np returns an error if the name is
longer. However, we're not in a context that can propagate errors when
we call this, and we used to implicitly truncate on Linux with prctl,
so now we manually truncate these names ahead of time.

r? @thomcc

These targets have system limits on the thread names, 16 and 64 bytes
respectively, and `pthread_setname_np` returns an error if the name is
longer. However, we're not in a context that can propagate errors when
we call this, and we used to implicitly truncate on Linux with `prctl`,
so now we manually truncate these names ahead of time.
@rustbot rustbot added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Oct 22, 2022
@rustbot

This comment was marked as resolved.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 22, 2022
@cuviper
Copy link
Member Author

cuviper commented Oct 22, 2022

The loss of prctl truncation since #100287 makes that a regression, headed for 1.65. We should either backport this change or revert to prctl on beta.

@rustbot label +beta-nominated

@rustbot rustbot added the beta-nominated Nominated for backporting to the compiler in the beta channel. label Oct 22, 2022
@thomcc
Copy link
Member

thomcc commented Oct 22, 2022

Looks good to me, thanks! (Kinda wild that 16 bytes is the norm on Linux, but so it goes)

@bors r+

@bors
Copy link
Contributor

bors commented Oct 22, 2022

📌 Commit 12e4584 has been approved by thomcc

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 Oct 22, 2022
notriddle added a commit to notriddle/rust that referenced this pull request Oct 22, 2022
…omcc

Truncate thread names on Linux and Apple targets

These targets have system limits on the thread names, 16 and 64 bytes
respectively, and `pthread_setname_np` returns an error if the name is
longer. However, we're not in a context that can propagate errors when
we call this, and we used to implicitly truncate on Linux with `prctl`,
so now we manually truncate these names ahead of time.

r? `@thomcc`
notriddle added a commit to notriddle/rust that referenced this pull request Oct 22, 2022
…omcc

Truncate thread names on Linux and Apple targets

These targets have system limits on the thread names, 16 and 64 bytes
respectively, and `pthread_setname_np` returns an error if the name is
longer. However, we're not in a context that can propagate errors when
we call this, and we used to implicitly truncate on Linux with `prctl`,
so now we manually truncate these names ahead of time.

r? ``@thomcc``
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Oct 22, 2022
…omcc

Truncate thread names on Linux and Apple targets

These targets have system limits on the thread names, 16 and 64 bytes
respectively, and `pthread_setname_np` returns an error if the name is
longer. However, we're not in a context that can propagate errors when
we call this, and we used to implicitly truncate on Linux with `prctl`,
so now we manually truncate these names ahead of time.

r? ```@thomcc```
@notriddle
Copy link
Contributor

Failed in rollup #103419 (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 Oct 23, 2022
@cuviper
Copy link
Member Author

cuviper commented Oct 23, 2022

Ah, musl added pthread_setname_np in 1.1.16, but pthread_getname_np wasn't added until 1.2.3, just this year. As that is only for a test, I think we can safely guard that for only linux-gnu.

@cuviper
Copy link
Member Author

cuviper commented Oct 23, 2022

Added that simple test gating...

@bors r=thomcc

@bors
Copy link
Contributor

bors commented Oct 23, 2022

📌 Commit 15cfeb3 has been approved by thomcc

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 23, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Oct 24, 2022
…omcc

Truncate thread names on Linux and Apple targets

These targets have system limits on the thread names, 16 and 64 bytes
respectively, and `pthread_setname_np` returns an error if the name is
longer. However, we're not in a context that can propagate errors when
we call this, and we used to implicitly truncate on Linux with `prctl`,
so now we manually truncate these names ahead of time.

r? `@thomcc`
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Oct 24, 2022
…omcc

Truncate thread names on Linux and Apple targets

These targets have system limits on the thread names, 16 and 64 bytes
respectively, and `pthread_setname_np` returns an error if the name is
longer. However, we're not in a context that can propagate errors when
we call this, and we used to implicitly truncate on Linux with `prctl`,
so now we manually truncate these names ahead of time.

r? ``@thomcc``
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Oct 24, 2022
…omcc

Truncate thread names on Linux and Apple targets

These targets have system limits on the thread names, 16 and 64 bytes
respectively, and `pthread_setname_np` returns an error if the name is
longer. However, we're not in a context that can propagate errors when
we call this, and we used to implicitly truncate on Linux with `prctl`,
so now we manually truncate these names ahead of time.

r? ```@thomcc```
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Oct 25, 2022
…omcc

Truncate thread names on Linux and Apple targets

These targets have system limits on the thread names, 16 and 64 bytes
respectively, and `pthread_setname_np` returns an error if the name is
longer. However, we're not in a context that can propagate errors when
we call this, and we used to implicitly truncate on Linux with `prctl`,
so now we manually truncate these names ahead of time.

r? ````@thomcc````
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Oct 25, 2022
…omcc

Truncate thread names on Linux and Apple targets

These targets have system limits on the thread names, 16 and 64 bytes
respectively, and `pthread_setname_np` returns an error if the name is
longer. However, we're not in a context that can propagate errors when
we call this, and we used to implicitly truncate on Linux with `prctl`,
so now we manually truncate these names ahead of time.

r? `````@thomcc`````
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 25, 2022
Rollup of 6 pull requests

Successful merges:

 - rust-lang#98204 (Stabilize `Option::unzip()`)
 - rust-lang#102587 (rustc: Use `unix_sigpipe` instead of `rustc_driver::set_sigpipe_handler`)
 - rust-lang#103122 (Remove misc_cast and validate types when casting)
 - rust-lang#103379 (Truncate thread names on Linux and Apple targets)
 - rust-lang#103482 (Clairify Vec::capacity docs)
 - rust-lang#103511 (Codegen tweaks)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 75023d6 into rust-lang:master Oct 25, 2022
@rustbot rustbot added this to the 1.66.0 milestone Oct 25, 2022
unsafe {
// Available since glibc 2.12, musl 1.1.16, and uClibc 1.0.20.
let name = truncate_cstr(name, TASK_COMM_LEN);
libc::pthread_setname_np(libc::pthread_self(), name.as_ptr());
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to at least debug_assert that no error is being returned here? Or even to assert that?

Copy link
Member Author

Choose a reason for hiding this comment

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

I would be fine with adding a debug_assert. I don't think it's worth a full assert though -- it could be blocked by seccomp or something, for whatever reason, but this isn't really a critical panic-worthy failure.

@m-ou-se m-ou-se added the beta-accepted Accepted for backporting to the compiler in the beta channel. label Oct 26, 2022
@Mark-Simulacrum Mark-Simulacrum removed the beta-nominated Nominated for backporting to the compiler in the beta channel. label Oct 29, 2022
@Mark-Simulacrum Mark-Simulacrum modified the milestones: 1.66.0, 1.65.0 Oct 29, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 29, 2022
…mulacrum

[beta] backport rollup

* poll_fn and Unpin: fix pinning rust-lang#102737
* Support raw-dylib functions being used inside inlined functions rust-lang#102988
* Fix line numbers for MIR inlined code rust-lang#103071
* Add architectures to fn create_object_file rust-lang#103240
* Add eval hack in super_relate_consts back rust-lang#103279
* Mark std::os::wasi::io::AsFd etc. as stable. rust-lang#103308
* Truncate thread names on Linux and Apple targets rust-lang#103379
* Do not consider repeated lifetime params for elision. rust-lang#103450
* rustdoc: add missing URL redirect rust-lang#103588
* Remove commit_if_ok probe from NLL type relation rust-lang#103601

Also includes a copy of the release notes.

r? `@ghost`
Aaron1011 pushed a commit to Aaron1011/rust that referenced this pull request Jan 6, 2023
…omcc

Truncate thread names on Linux and Apple targets

These targets have system limits on the thread names, 16 and 64 bytes
respectively, and `pthread_setname_np` returns an error if the name is
longer. However, we're not in a context that can propagate errors when
we call this, and we used to implicitly truncate on Linux with `prctl`,
so now we manually truncate these names ahead of time.

r? ``````@thomcc``````
Aaron1011 pushed a commit to Aaron1011/rust that referenced this pull request Jan 6, 2023
Rollup of 6 pull requests

Successful merges:

 - rust-lang#98204 (Stabilize `Option::unzip()`)
 - rust-lang#102587 (rustc: Use `unix_sigpipe` instead of `rustc_driver::set_sigpipe_handler`)
 - rust-lang#103122 (Remove misc_cast and validate types when casting)
 - rust-lang#103379 (Truncate thread names on Linux and Apple targets)
 - rust-lang#103482 (Clairify Vec::capacity docs)
 - rust-lang#103511 (Codegen tweaks)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@cuviper cuviper deleted the truncate-thread-name branch May 21, 2023 03:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beta-accepted Accepted for backporting to the compiler in the beta channel. 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.

None yet

9 participants