Skip to content

Commit

Permalink
fix u64 overflow bug
Browse files Browse the repository at this point in the history
  • Loading branch information
xudesheng committed May 5, 2022
1 parent 22ccc96 commit 5e8ed53
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tsample"
version = "4.2.3"
version = "4.2.4"
authors = ["xudesheng <[email protected]>"]
edition = "2021"
readme = "README.md"
Expand Down
5 changes: 3 additions & 2 deletions src/twxquery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 5e8ed53

Please sign in to comment.