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

[incremental] Don't panic if decoding the cache fails #49364

Merged
merged 1 commit into from
Mar 29, 2018

Conversation

wesleywiser
Copy link
Member

If the cached data can't be loaded from disk, just issue a warning to
the user so they know why compilation is taking longer than usual but
don't fail the entire compilation since we can recover by ignorning the
on disk cache.

In the same way, if the disk cache can't be deserialized (because it has
been corrupted for some reason), report the issue as a warning and
continue without failing the compilation. Decodable::decode() tends to
panic with various errors like "entered unreachable code" or "index out
of range" if the input data is corrupted. Work around this by catching
panics from the decode() calls and continuing without the cached data.

Fixes #48847

@rust-highfive
Copy link
Collaborator

r? @cramertj

(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 Mar 25, 2018
@cramertj
Copy link
Member

Not sure who to give this to, but definitely not me, so r? @michaelwoerister


MaybeAsync::Async(std::thread::spawn(move || {
time_ext(time_passes, None, "background load prev dep-graph", move || {
panic::catch_unwind(load).unwrap_or_else(
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to catch the unwind? Can't we just handle this on thread.join() since we're paying that cost anyway?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a good idea! I will do some testing and see if that works.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that's a good suggestion.

MaybeAsync::Async(std::thread::spawn(move || {
time_ext(time_passes, None, "background load prev dep-graph", move || {
panic::catch_unwind(load).unwrap_or_else(
|_| LoadResult::Error { message: "could not decode incremental cache".into() })
Copy link
Contributor

Choose a reason for hiding this comment

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

Please emit the actual panic via a debug! or even info! call, so we can figure out what's going on without needing to rebuild the compiler.

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 couldn't figure out a way to do this. I tried doing formatting the error into the message with format!("could not decode incremental cache: {:?}", e) but that just printed "could not decode incremental cache: Any".

Copy link
Member

Choose a reason for hiding this comment

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

Maybe someone for @rust-lang/libs knows how to do this best?

Copy link
Member

Choose a reason for hiding this comment

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

There's currently no easy way to get out the message of a Box<Any> unfortunately, but we also tend to recommend against using catch_unwind for error handling like this and would instead recommend returning an Err all the way up (which can then be printed)

Copy link
Member Author

Choose a reason for hiding this comment

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

The panic handler for the thread is still running so the compiler output looks like this:

   Compiling webrender v0.57.0 (file:///Users/wesley/code/rust/temp3/webrender/webrender)
thread '<unnamed>' panicked at 'internal error: entered unreachable code', librustc/dep_graph/dep_node.rs:124:34
note: Run with `RUST_BACKTRACE=1` for a backtrace.
warning: could not decode incremental cache

@michaelwoerister
Copy link
Member

Thanks for the PR, @wesleywiser! I'll take a look shortly.

@michaelwoerister
Copy link
Member

Thanks, @wesleywiser!

@bors r+

@bors
Copy link
Contributor

bors commented Mar 28, 2018

📌 Commit 369f34c has been approved by michaelwoerister

@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 Mar 28, 2018
If the cached data can't be loaded from disk, just issue a warning to
the user so they know why compilation is taking longer than usual but
don't fail the entire compilation since we can recover by ignorning the
on disk cache.

In the same way, if the disk cache can't be deserialized (because it has
been corrupted for some reason), report the issue as a warning and
continue without failing the compilation. `Decodable::decode()` tends to
panic with various errors like "entered unreachable code" or "index out
of range" if the input data is corrupted. Work around this by catching
panics from the `decode()` calls when joining the thread and continuing
without the cached data.

Fixes rust-lang#48847
@wesleywiser
Copy link
Member Author

Rebased

@michaelwoerister
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Mar 28, 2018

📌 Commit 49fd71b has been approved by michaelwoerister

kennytm added a commit to kennytm/rust that referenced this pull request Mar 28, 2018
…e, r=michaelwoerister

[incremental] Don't panic if decoding the cache fails

If the cached data can't be loaded from disk, just issue a warning to
the user so they know why compilation is taking longer than usual but
don't fail the entire compilation since we can recover by ignorning the
on disk cache.

In the same way, if the disk cache can't be deserialized (because it has
been corrupted for some reason), report the issue as a warning and
continue without failing the compilation. `Decodable::decode()` tends to
panic with various errors like "entered unreachable code" or "index out
of range" if the input data is corrupted. Work around this by catching
panics from the `decode()` calls and continuing without the cached data.

Fixes rust-lang#48847
bors added a commit that referenced this pull request Mar 28, 2018
Rollup of 12 pull requests

- Successful merges: #49243, #49329, #49364, #49400, #49405, #49427, #49428, #49429, #49439, #49442, #49444, #49452
- Failed merges:
@bors bors merged commit 49fd71b into rust-lang:master Mar 29, 2018
@jsgf
Copy link
Contributor

jsgf commented Mar 29, 2018

Thanks for fixing this!

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.

9 participants