tokio-rs / tokio

A runtime for writing reliable asynchronous applications with Rust. Provides I/O, networking, scheduling, timers, ...
https://tokio.rs
MIT License
25.71k stars 2.35k forks source link

time: fix big time panic issue #6612

Closed wathenjiang closed 1 month ago

wathenjiang commented 1 month ago

Motivation

The https://github.com/tokio-rs/tokio/pull/5710 tried to fix the panic issue when the instance is very big.

However, the instant_to_tick can still calculate a u64 which is bigger than MAX_SAFE_MILLIS_DURATION.

Solution

Even if a u128 successfully try_into a u64, we still check whether it is bigger than MAX_SAFE_MILLIS_DURATION. If it is greater, we will return MAX_SAFE_MILLIS_DURATION.