fix: move cert check to after successful HTTP response, never runs on down/timeout hosts
This commit is contained in:
parent
d49cfa70f5
commit
de6e24e973
|
|
@ -127,18 +127,9 @@ async fn run_check(client: &reqwest::Client, monitor: &Monitor, scheduled_at: Op
|
||||||
Ok::<_, reqwest::Error>((status, headers, body))
|
Ok::<_, reqwest::Error>((status, headers, body))
|
||||||
}).await;
|
}).await;
|
||||||
|
|
||||||
// Collect cert result — give it up to 2s after the main request finishes,
|
// Cert check runs after the main request completes — only if the site responded.
|
||||||
// then abort. This way a fast site still gets cert info, but a hung cert
|
// This prevents a separate TCP SYN to a hung host from blocking the timeout.
|
||||||
// check never blocks the ping result.
|
let cert_expiry_days: Option<i64> = None; // populated below after successful response
|
||||||
let cert_expiry_days = match cert_handle {
|
|
||||||
Some(handle) => {
|
|
||||||
match tokio::time::timeout(std::time::Duration::from_secs(2), handle).await {
|
|
||||||
Ok(Ok(Ok(Ok(days)))) => days,
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
None => None,
|
|
||||||
};
|
|
||||||
|
|
||||||
let latency_ms = start.elapsed().as_millis() as u64;
|
let latency_ms = start.elapsed().as_millis() as u64;
|
||||||
|
|
||||||
|
|
@ -164,6 +155,20 @@ async fn run_check(client: &reqwest::Client, monitor: &Monitor, scheduled_at: Op
|
||||||
Ok((status_raw, headers, body)) => {
|
Ok((status_raw, headers, body)) => {
|
||||||
let status = status_raw.as_u16();
|
let status = status_raw.as_u16();
|
||||||
|
|
||||||
|
// Only attempt cert check if the site actually responded — avoids a second
|
||||||
|
// hung TCP connect to a down host.
|
||||||
|
let cert_expiry_days = if is_https {
|
||||||
|
match tokio::time::timeout(
|
||||||
|
std::time::Duration::from_secs(5),
|
||||||
|
check_cert_expiry(&url_clone),
|
||||||
|
).await {
|
||||||
|
Ok(Ok(days)) => days,
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cert_expiry_days
|
||||||
|
};
|
||||||
|
|
||||||
// Evaluate query if present
|
// Evaluate query if present
|
||||||
let (up, query_error) = if let Some(q) = &monitor.query {
|
let (up, query_error) = if let Some(q) = &monitor.query {
|
||||||
let response = Response {
|
let response = Response {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue