From 5e8ed5364277a53758cc55b1b598c9e53cb58aa4 Mon Sep 17 00:00:00 2001 From: Xu Desheng <8742037+xudesheng@users.noreply.github.com> Date: Thu, 5 May 2022 14:00:57 -0400 Subject: [PATCH] fix u64 overflow bug --- CHANGELOG.md | 6 ++++++ Cargo.lock | 2 +- Cargo.toml | 2 +- src/twxquery.rs | 5 +++-- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c7d415..e98211b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] ### Added + +## [v4.2.4] - 2022-05-05 + +### Changed + - Fixed the bug: when a query is timed out, the sleep time was not being reset due to u64 overflow. + ## [v4.2.3] - 2022-04-07 ### Added diff --git a/Cargo.lock b/Cargo.lock index 52a47c8..0a7c560 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -994,7 +994,7 @@ checksum = "e604eb7b43c06650e854be16a2a03155743d3752dd1c943f6829e26b7a36e382" [[package]] name = "tsample" -version = "4.2.3" +version = "4.2.4" dependencies = [ "anyhow", "chrono", diff --git a/Cargo.toml b/Cargo.toml index e1db4c0..d4c0abc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tsample" -version = "4.2.3" +version = "4.2.4" authors = ["xudesheng "] edition = "2021" readme = "README.md" diff --git a/src/twxquery.rs b/src/twxquery.rs index 2986253..1362cfd 100644 --- a/src/twxquery.rs +++ b/src/twxquery.rs @@ -178,8 +178,9 @@ pub async fn launch_twxquery_service( break; } let spent_time = SystemTime::now().duration_since(start_time).unwrap(); - let sleep_time = scrap_interval * 1000 - spent_time.as_millis() as u64; - if sleep_time > 0 { + + if scrap_interval * 1000 > spent_time.as_millis() as u64 { + let sleep_time = scrap_interval * 1000 - spent_time.as_millis() as u64; log::info!("sleep {} seconds", sleep_time/1000); sleeping.store(true, Ordering::SeqCst); tokio::time::sleep(std::time::Duration::from_millis(sleep_time)).await;