Skip to content

Commit 43c8f8b

Browse files
author
Thomas Luijken
committed
Make sure the thread sleep doesn't get negative values at runtime
1 parent fc2d275 commit 43c8f8b

2 files changed

Lines changed: 25 additions & 17 deletions

File tree

oxybox/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "oxybox"
3-
version = "1.0.5"
3+
version = "1.0.6"
44
authors = ["Thomas Luijken"]
55
categories = ["command-line-utilities"]
66
description = "A drop in replacement for blackbox exporter for Prometheus, with support for TLS and HTTP/3."

oxybox/src/http_probe/probe.rs

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -243,30 +243,38 @@ pub async fn run_probe_loop(
243243
let org_id = org_config.organisation_id.clone();
244244
let mimir_endpoint = mimir_endpoint.clone();
245245

246-
let probe_timeout_duration: Duration = Duration::from_secs(org_config.polling_interval_seconds);
247-
248-
handles.push(tokio::spawn(tokio::time::timeout(probe_timeout_duration, async move {
249-
handle_target_probe(
250-
tenant_name,
251-
&org_id,
252-
&target,
253-
&connector,
254-
&resolver,
255-
&mimir_endpoint,
256-
max_org_width,
257-
)
258-
.await;
259-
})));
246+
let probe_timeout_duration: Duration =
247+
Duration::from_secs(org_config.polling_interval_seconds);
248+
249+
handles.push(tokio::spawn(tokio::time::timeout(
250+
probe_timeout_duration,
251+
async move {
252+
handle_target_probe(
253+
tenant_name,
254+
&org_id,
255+
&target,
256+
&connector,
257+
&resolver,
258+
&mimir_endpoint,
259+
max_org_width,
260+
)
261+
.await;
262+
},
263+
)));
260264
}
261265

262266
for handle in handles {
263267
if let Err(join_err) = handle.await {
264268
log::error!("Task panicked: {:?}", join_err);
265269
}
266270
}
267-
let elapsed = start_time.elapsed();
271+
let elapsed = start_time.elapsed().as_secs();
272+
let wait = org_config
273+
.polling_interval_seconds
274+
.checked_sub(elapsed)
275+
.unwrap_or(0);
268276

269-
sleep(Duration::from_secs(org_config.polling_interval_seconds - elapsed.as_secs())).await;
277+
sleep(Duration::from_secs(wait)).await;
270278
}
271279
}
272280

0 commit comments

Comments
 (0)