mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-12-03 20:30:11 +08:00
A caller could sample the clock at 1000 ms and pause while another caller was admitted at 2000 ms. On resuming, the first caller could load the newer last_run_ms, mistake its stale sample for a clock rollback, and replace 2000 with 1000. This reopened the 100 ms period and let another check at 2000 ms pass. Load last_run_ms before sampling the clock so the stale caller's compare-exchange fails if a newer admission has changed that value. Preserve sequential clock rollback behavior and the existing atomic orderings. The period check also added the period to last_run_ms. A last admission at u64::MAX - 55 with a 56 ms period overflowed on the next check: debug builds panicked and release builds wrapped the deadline to zero, admitting a duplicate timestamp. Compare elapsed time against the period only after confirming the clock has not moved backward, which makes the subtraction safe and preserves the exact period boundary. Enable the stale-sample and overflow regressions, keep the saved Proptest seed, and add Loom coverage for advancing time and multiple stale callers plus a deterministic test at u64::MAX.