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

Never panic in thread::park and thread::park_timeout #102412

Merged
merged 1 commit into from
Oct 11, 2022

Conversation

joboet
Copy link
Member

@joboet joboet commented Sep 28, 2022

fixes #102398

@rustbot label +T-libs +T-libs-api

@rustbot rustbot added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Sep 28, 2022
@rustbot
Copy link
Collaborator

rustbot commented Sep 28, 2022

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@rust-highfive
Copy link
Contributor

r? @m-ou-se

(rust-highfive has picked a reviewer for you, use r? to override)

@rustbot rustbot added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Sep 28, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 28, 2022
@the8472
Copy link
Member

the8472 commented Sep 28, 2022

Wouldn't not parking the thread if some underlying resource can't be acquired be a valid strategy? After all park is allowed to wake up any time, similar to condvars. So instead of panicing it would return immediately.

@m-ou-se
Copy link
Member

m-ou-se commented Sep 28, 2022

@the8472 Yes, but if the error keeps occuring, that'd effectively turn a park-loop into a spin-loop, which is pretty bad.

@m-ou-se
Copy link
Member

m-ou-se commented Sep 30, 2022

Changing the implementation to never panic looks good to me. Making it a documented guarantee should go through FCP though.

@rfcbot merge

This FCP is for documenting the guarantee that thread::park() (and thread::park_timeout()) will never panic. See #102398 for context.

@rfcbot
Copy link
Collaborator

rfcbot commented Sep 30, 2022

Team member @m-ou-se has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Sep 30, 2022
@rfcbot
Copy link
Collaborator

rfcbot commented Oct 1, 2022

🔔 This is now entering its final comment period, as per the review above. 🔔

@joboet
Copy link
Member Author

joboet commented Oct 3, 2022

Wouldn't not parking the thread if some underlying resource can't be acquired be a valid strategy? After all park is allowed to wake up any time, similar to condvars. So instead of panicing it would return immediately.

Yes, definitely, and this is still valid behaviour. However, since implementing that would impact so many different areas (TLS for instance), I doubt that it is really worth it, as errors should be extremely rare here.

@DemiMarie
Copy link
Contributor

Wouldn't not parking the thread if some underlying resource can't be acquired be a valid strategy? After all park is allowed to wake up any time, similar to condvars. So instead of panicing it would return immediately.

Yes, definitely, and this is still valid behaviour. However, since implementing that would impact so many different areas (TLS for instance), I doubt that it is really worth it, as errors should be extremely rare here.

What about eagerly allocating the resources when creating the thread?

@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Oct 11, 2022
@rfcbot
Copy link
Collaborator

rfcbot commented Oct 11, 2022

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

This will be merged soon.

@rfcbot rfcbot added the to-announce Announce this issue on triage meeting label Oct 11, 2022
@m-ou-se
Copy link
Member

m-ou-se commented Oct 11, 2022

What about eagerly allocating the resources when creating the thread?

That doesn't prevent all possible panics. We can't guarantee that e.g. the underlying libc calls always succeed. See #102398 (comment)

@m-ou-se
Copy link
Member

m-ou-se commented Oct 11, 2022

@bors r+

@bors
Copy link
Collaborator

bors commented Oct 11, 2022

📌 Commit b0b9f5b has been approved by m-ou-se

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 11, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Oct 11, 2022
Never panic in `thread::park` and `thread::park_timeout`

fixes rust-lang#102398

``@rustbot`` label +T-libs +T-libs-api
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 11, 2022
Rollup of 7 pull requests

Successful merges:

 - rust-lang#102258 (Remove unused variable in float formatting.)
 - rust-lang#102277 (Consistently write `RwLock`)
 - rust-lang#102412 (Never panic in `thread::park` and `thread::park_timeout`)
 - rust-lang#102589 (scoped threads: pass closure through MaybeUninit to avoid invalid dangling references)
 - rust-lang#102625 (fix backtrace small typo)
 - rust-lang#102859 (Move lifetime resolution module to rustc_hir_analysis.)
 - rust-lang#102898 (rustdoc: remove unneeded `<div>` wrapper from sidebar DOM)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit e0954ca into rust-lang:master Oct 11, 2022
@rustbot rustbot added this to the 1.66.0 milestone Oct 11, 2022
@joboet joboet deleted the dont_panic branch October 19, 2022 19:14
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Jan 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. 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. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

thread::park causes undefined behaviour on panic
9 participants