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

Gracefully handle errors during a build. #8247

Merged
merged 2 commits into from
May 18, 2020
Merged

Conversation

ehuss
Copy link
Contributor

@ehuss ehuss commented May 16, 2020

If there are certain errors like EPIPE during a build, Cargo runs the risk of hanging if the compiler emits too many messages. This happens because Cargo now uses a bounded queue for compiler messages. However, if the main loop exits while the threads are running, there is nothing to drain the queue, and thus the threads will block indefinitely.

The solution here is to be extra careful of how errors are handled in the main loop. All errors are now treated roughly the same (report the error, allow the queue to continue to drain).

I've also tweaked things so the first error is reported, not the last.

Closes #8245

@rust-highfive
Copy link

r? @Eh2406

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 16, 2020
@Eh2406
Copy link
Contributor

Eh2406 commented May 17, 2020

Seams reasonable to me.

Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

This looks great to me, thanks for this! I've got just one stylistic nit about refactoring this to statically prevent ?, but other than that r=me as well.

@@ -651,25 +635,33 @@ impl<'cfg> DrainState<'cfg> {
// successful and otherwise wait for pending work to finish if it failed
// and then immediately return.
let mut error = None;
// CAUTION! From here on out, do not use `?`. Every error must be handled
Copy link
Member

Choose a reason for hiding this comment

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

Could this loop get factored into a function that doesn't return Result to statically prevent usage of ??

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated, WDYT? I assume Result will never be changed to implement Try such that it calls result.ok() to convert a Result to Option automatically?

@alexcrichton
Copy link
Member

@bors: r+

Looks great to me!

I highly doubt that auto-conversion will ever be added, but even so we've got a nice comment explaining to be vigilant anyway

@bors
Copy link
Collaborator

bors commented May 18, 2020

📌 Commit 5e561ae has been approved by alexcrichton

@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 May 18, 2020
@bors
Copy link
Collaborator

bors commented May 18, 2020

⌛ Testing commit 5e561ae with merge b781ec4...

@bors
Copy link
Collaborator

bors commented May 18, 2020

☀️ Test successful - checks-azure
Approved by: alexcrichton
Pushing b781ec4 to master...

@bors bors merged commit b781ec4 into rust-lang:master May 18, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request May 20, 2020
Update cargo

9 commits in cb06cb2696df2567ce06d1a39b1b40612a29f853..500b2bd01c958f5a33b6aa3f080bea015877b83c
2020-05-08 21:57:44 +0000 to 2020-05-18 17:12:54 +0000
- Handle LTO with an rlib/cdylib crate type (rust-lang/cargo#8254)
- Gracefully handle errors during a build. (rust-lang/cargo#8247)
- Update `im-rc` to 15.0.0 (rust-lang/cargo#8255)
- Fix `cargo update` with unused patch. (rust-lang/cargo#8243)
- Rephrased error message for disallowed sections in virtual workspace (rust-lang/cargo#8200)
- Ignore broken console output in some situations. (rust-lang/cargo#8236)
- Expand error message to explain that a string was found (rust-lang/cargo#8235)
- Add context to some fs errors. (rust-lang/cargo#8232)
- Move SipHasher to an isolated module. (rust-lang/cargo#8233)
@ehuss ehuss added this to the 1.45.0 milestone Feb 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hangs if procedural macro prints output when stdout is closed
5 participants