[control] Fix round 4: a device change during an engine switch is never skipped silently (devices_problem until the serving engine is told), and every switch ends by telling the engine that serves, also after going back
This commit is contained in:
@@ -193,12 +193,38 @@ impl Control {
|
|||||||
Err(_) => Some(self.engine_lock.lock().await),
|
Err(_) => Some(self.engine_lock.lock().await),
|
||||||
};
|
};
|
||||||
// Tell the serving engine every time, changed or not: a repeated Revoke nudges again.
|
// Tell the serving engine every time, changed or not: a repeated Revoke nudges again.
|
||||||
|
// During a switch it is not told now, and never silently (QC round 4): the problem
|
||||||
|
// stays set, so the retry tells whichever engine serves once the switch is over (the
|
||||||
|
// switch itself also ends by telling it).
|
||||||
|
let mut pending = None;
|
||||||
if result.is_ok() {
|
if result.is_ok() {
|
||||||
|
if engine.is_none() {
|
||||||
|
pending = Some(
|
||||||
|
"an engine switch is under way; the engine that serves after it is told then"
|
||||||
|
.to_owned(),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
result = self.nudge_devices().await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Ok(mut pr) = self.devices_problem.lock() {
|
||||||
|
*pr = result.as_ref().err().cloned().or(pending.clone());
|
||||||
|
}
|
||||||
|
if let Some(p) = &pending {
|
||||||
|
log::info!(target: "ianitor::pki", "{p}");
|
||||||
|
}
|
||||||
|
if let Err(e) = &result {
|
||||||
|
log::error!(target: "ianitor::pki", "{e}; retrying");
|
||||||
|
}
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Tell the engine that serves to read the device files again. The caller holds the engine
|
||||||
|
/// lock. Under Caddy with a trial out, the end of that apply does it (promote, revert, the
|
||||||
|
/// guard and caddy-revert all load caddy.json, which reads the files).
|
||||||
|
pub(crate) async fn nudge_devices(&self) -> Result<(), String> {
|
||||||
let caddy = self.engine_running() == "caddy";
|
let caddy = self.engine_running() == "caddy";
|
||||||
result = if engine.is_none() {
|
if caddy && crate::caddy_guard::armed(&self.cfg.state_dir).is_some() {
|
||||||
log::info!(target: "ianitor::pki", "an engine switch is under way; the engine it starts reads the new device list");
|
|
||||||
Ok(())
|
|
||||||
} else if caddy && crate::caddy_guard::armed(&self.cfg.state_dir).is_some() {
|
|
||||||
log::info!(target: "ianitor::pki", "a change is being tried on Caddy; Caddy reads the new device list when it ends");
|
log::info!(target: "ianitor::pki", "a change is being tried on Caddy; Caddy reads the new device list when it ends");
|
||||||
Ok(())
|
Ok(())
|
||||||
} else if caddy {
|
} else if caddy {
|
||||||
@@ -212,15 +238,7 @@ impl Control {
|
|||||||
.map_err(|e| format!("edge did not re-read the device list: {e}"))
|
.map_err(|e| format!("edge did not re-read the device list: {e}"))
|
||||||
} else {
|
} else {
|
||||||
Ok(())
|
Ok(())
|
||||||
};
|
|
||||||
}
|
}
|
||||||
if let Ok(mut pr) = self.devices_problem.lock() {
|
|
||||||
*pr = result.as_ref().err().cloned();
|
|
||||||
}
|
|
||||||
if let Err(e) = &result {
|
|
||||||
log::error!(target: "ianitor::pki", "{e}; retrying");
|
|
||||||
}
|
|
||||||
result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn reload_serving_engine(&self) {
|
async fn reload_serving_engine(&self) {
|
||||||
|
|||||||
@@ -254,6 +254,17 @@ impl Control {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Still under the engine lock: whichever engine serves now reads the device files again
|
||||||
|
// (QC round 4). A device change during the switch only wrote them; a Caddy that was
|
||||||
|
// already running, or started before they changed, would keep the old list.
|
||||||
|
if self.pki.is_some()
|
||||||
|
&& let Err(e) = self.nudge_devices().await
|
||||||
|
{
|
||||||
|
log::error!(target: "ianitor::engine", "after the switch: {e}; retrying");
|
||||||
|
if let Ok(mut p) = self.devices_problem.lock() {
|
||||||
|
*p = Some(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn units_and_cfg(&self) -> Result<(Arc<dyn Units>, EngineConfig), String> {
|
fn units_and_cfg(&self) -> Result<(Arc<dyn Units>, EngineConfig), String> {
|
||||||
|
|||||||
@@ -78,6 +78,12 @@ esac
|
|||||||
let deadline = Instant::now() + Duration::from_secs(30);
|
let deadline = Instant::now() + Duration::from_secs(30);
|
||||||
loop {
|
loop {
|
||||||
let r = env.call("GET", "/api/v1/engine", None).await;
|
let r = env.call("GET", "/api/v1/engine", None).await;
|
||||||
|
// On a loaded machine a switch takes longer: stay under the API's 120 calls a
|
||||||
|
// minute rather than fail on a 429.
|
||||||
|
if r.status == 429 {
|
||||||
|
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
assert_eq!(r.status, 200, "{}", r.text);
|
assert_eq!(r.status, 200, "{}", r.text);
|
||||||
if r.json["state"] == "running" && r.json["running"] == running {
|
if r.json["state"] == "running" && r.json["running"] == running {
|
||||||
return r.json;
|
return r.json;
|
||||||
@@ -85,7 +91,7 @@ esac
|
|||||||
if Instant::now() > deadline {
|
if Instant::now() > deadline {
|
||||||
panic!("engine is {}\n{}", r.text, env.control_log());
|
panic!("engine is {}\n{}", r.text, env.control_log());
|
||||||
}
|
}
|
||||||
tokio::time::sleep(Duration::from_millis(100)).await;
|
tokio::time::sleep(Duration::from_millis(300)).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -654,7 +660,7 @@ esac
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
assert!(Instant::now() < deadline, "never {state}: {}", r.text);
|
assert!(Instant::now() < deadline, "never {state}: {}", r.text);
|
||||||
tokio::time::sleep(Duration::from_millis(100)).await;
|
tokio::time::sleep(Duration::from_millis(250)).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-1
@@ -309,7 +309,10 @@ allows exactly `ianitor-edge.service` and `caddy-fallback.service`, verbs start
|
|||||||
waits until it serves; if it does not within 20 s, it starts the old one again and reports
|
waits until it serves; if it does not within 20 s, it starts the old one again and reports
|
||||||
`engine.switch_failed`. The switch waits for a running apply (same lock, first come first
|
`engine.switch_failed`. The switch waits for a running apply (same lock, first come first
|
||||||
served: a queued switch runs right after the apply in progress, before any apply queued after
|
served: a queued switch runs right after the apply in progress, before any apply queued after
|
||||||
it). Back on Pingora, edge is reloaded so it serves what was applied while Caddy served.
|
it). Back on Pingora, edge is reloaded so it serves what was applied while Caddy served. Every
|
||||||
|
switch, kept or gone back, ends by telling the engine that serves to read the device files again;
|
||||||
|
a device change during a switch only writes them and shows `devices_problem` ("an engine switch is
|
||||||
|
under way") until then, and the 2 s retry tells the serving engine too.
|
||||||
Refusals: `engine.unmanaged` (no `[engine]` in control.toml), `engine.same`, `engine.switching`,
|
Refusals: `engine.unmanaged` (no `[engine]` in control.toml), `engine.same`, `engine.switching`,
|
||||||
`engine.not_ready` (Caddy's settings cannot be built from the current routes).
|
`engine.not_ready` (Caddy's settings cannot be built from the current routes).
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user