pub fn probe_patiently(
url: &str,
root: &Path,
pid: u32,
patience: Duration,
) -> boolExpand description
probe, with patience for an owner that is alive but slow.
A probe that times out says nothing about whether the server is gone: a server loading
a large layer, or one on a machine under load (an instrumented test run, a loaded CI
runner), answers late. Judging it gone from one silent probe makes serve ensure start
a second server beside it and report the old one’s address as though it had started it.
So when the probe fails and the lease’s pid is a live process on this machine, the
probe is repeated every second for up to patience — the caller’s share of
Timings::busy_grace, the same wait the election gives a busy owner. The answer is
false only when every attempt fails.
The patience is bounded on purpose. A live pid can be a wedged server that never answers
again, and a probe that waited on it forever would make every client hang on a ghost. A
dead pid, or pid 0, gets no patience at all, so a killed server is recovered at once,
and a patience of zero is a single probe.
use majordomus_cli::lease::probe_patiently;
use std::path::Path;
use std::time::{Duration, Instant};
// nothing listens on port 1 and pid 0 names no process: one refused probe, no patience
let t0 = Instant::now();
let patience = Duration::from_secs(10);
assert!(!probe_patiently("http://127.0.0.1:1", Path::new("/nowhere"), 0, patience));
assert!(t0.elapsed() < Duration::from_secs(5));