Skip to content

Conversation

@matheus23
Copy link
Contributor

@matheus23 matheus23 commented Nov 3, 2025

Addresses the failure in #2434

Subtractions from Instant can underflow (and thus panic), because the u64 stored internally might be relative to some startup time that might be too recent.

This is what caused the failure in Wasm: The instant was relative to the process startup time, in one case ~15s, but the loss_delay was set to ~17s in that case.

Instead, this PR aims to compare the saturated difference of now and info.time_sent, and see if that's bigger than loss_delay or not.

Unfortunately I don't know of a different way of resolving this. There's no such thing as Instant::saturating_sub, and there's no Instant::MIN or similar with which it could be implemented.

Even though this addresses a problem in Wasm, this case can also happen in MacOS and other platforms, but requires different, less common edge-cases to trigger.

@matheus23 matheus23 force-pushed the matheus23/fix-instant-underflow branch from 3f73e13 to cec9619 Compare November 3, 2025 13:16
@matheus23
Copy link
Contributor Author

I messed up the computation ever so slightly with a > instead of a >=. I fixed it and now tests shouldn't hang.

@matheus23 matheus23 force-pushed the matheus23/fix-instant-underflow branch from cec9619 to c53e8d6 Compare November 3, 2025 13:23
@matheus23 matheus23 force-pushed the matheus23/fix-instant-underflow branch from c53e8d6 to 592e56a Compare November 3, 2025 13:41
flub added a commit to n0-computer/quinn that referenced this pull request Nov 4, 2025
Ported from quinn-rs#2436

* Remove `instant_saturating_sub` fn in favor of `Instant::saturating_duration_since`

* Avoid underflow panic in packet loss `Instant` calculations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants