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 2 times, most recently 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
@matheus23 matheus23 force-pushed the matheus23/fix-instant-underflow branch from 9e329ee to 815f263 Compare November 10, 2025 14:05
Copy link
Member

@djc djc left a comment

Choose a reason for hiding this comment

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

Thanks for the iterations!

@Ralith want to have a quick look?

Copy link
Collaborator

@Ralith Ralith left a comment

Choose a reason for hiding this comment

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

Nice, thanks!

@Ralith Ralith added this pull request to the merge queue Nov 11, 2025
Merged via the queue into quinn-rs:main with commit b699e5c Nov 11, 2025
19 checks passed
@matheus23 matheus23 deleted the matheus23/fix-instant-underflow branch November 11, 2025 07:39
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.

4 participants