-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Conversation
r? @Eh2406 (rust_highfive has picked a reviewer for you, use r? to override) |
Seams reasonable to me. |
There was a problem hiding this 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.
src/cargo/core/compiler/job_queue.rs
Outdated
@@ -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 |
There was a problem hiding this comment.
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 ?
?
There was a problem hiding this comment.
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?
@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 |
📌 Commit 5e561ae has been approved by |
☀️ Test successful - checks-azure |
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)
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