Skip to content

Don't panic in duration underflow#12693

Open
ConradIrwin wants to merge 1 commit intobytecodealliance:mainfrom
ConradIrwin:fix-interval-duration
Open

Don't panic in duration underflow#12693
ConradIrwin wants to merge 1 commit intobytecodealliance:mainfrom
ConradIrwin:fix-interval-duration

Conversation

@ConradIrwin
Copy link

In debug mode we check for tokens being dropped out of order, but in a
release build this can fail.

Closes #12692

In debug mode we check for tokens being dropped out of order, but in a
release build this can fail.
@ConradIrwin ConradIrwin requested a review from a team as a code owner February 27, 2026 23:32
@ConradIrwin ConradIrwin requested review from cfallin and removed request for a team February 27, 2026 23:32
@cfallin
Copy link
Member

cfallin commented Feb 28, 2026

Thanks for your report and this PR!

I don't think any of the current contributors have touched this code in a while so we may not have a full understanding of its invariants, but I'm surprised that "tokens are dropped out of order" -- do you have a reproduction of that? (I see your companion issue filed said you had no repro, but maybe you do with this PR?)

In any case, I'm happy to merge it as a conservative fix but I'd like to understand if there's an underlying invariant violation that it would mask first, too.

@cfallin
Copy link
Member

cfallin commented Feb 28, 2026

(As an aside, I'm also surprised you're seeing this in (presumably production) telemetry -- is the timing infra enabled in your configuration?)

@github-actions github-actions bot added the cranelift Issues related to the Cranelift code generator label Feb 28, 2026
@ConradIrwin
Copy link
Author

@cfallin no reproduction, just a somewhat surprising crash showed up in our telemetry.

I think timings are logged if RUST_LOG=debug is exported (regardless of build settings), which seems plausible for a Zed user working on Rust.

Claude's (very hand-wavy) explanation for the out of order timing was that as these things happen on different threads, the drop ordering was not guaranteed; but not sure I believe it. (It seems like some care is taken to avoid this, hence the debug assert here: https://github.com/ConradIrwin/wasmtime/blob/c5214df981a88d30226e9b3ac1b88da32395806a/cranelift/codegen/src/timing.rs#L269).

The other potential options are something weird with instants (e.g. this purported issue zed-industries/zed#46636); or given this has only happened once, a particularly targeted cosmic ray.

@cfallin
Copy link
Member

cfallin commented Feb 28, 2026

Claude's (very hand-wavy) explanation for the out of order timing was that as these things happen on different threads, the drop ordering was not guaranteed; but not sure I believe it. (It seems like some care is taken to avoid this, hence the debug assert here: https://github.com/ConradIrwin/wasmtime/blob/c5214df981a88d30226e9b3ac1b88da32395806a/cranelift/codegen/src/timing.rs#L269).

OK, that's fortunately not possible -- Claude must not have seen the thread_local! on the relevant data structure here, such that compilations in different threads never interact. Drop order should be purely a function of the (hopefully deterministic!) pass driver structure in one compilation in one thread.

I'll take a closer look at this code and try to understand its invariants next week -- in the meantime, any further info you can gather about repros or conditions this is seen under are of course appreciated. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cranelift Issues related to the Cranelift code generator

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cranelift: panic calculating timing total

2 participants