[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,29 +193,25 @@ impl Control {
|
||||
Err(_) => Some(self.engine_lock.lock().await),
|
||||
};
|
||||
// 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() {
|
||||
let caddy = self.engine_running() == "caddy";
|
||||
result = if engine.is_none() {
|
||||
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");
|
||||
Ok(())
|
||||
} else if caddy {
|
||||
self.caddy_reload_checked()
|
||||
.await
|
||||
.map_err(|e| format!("Caddy did not reload the device list: {e}"))
|
||||
} else if self.edge.attached() {
|
||||
self.edge
|
||||
.reload_devices()
|
||||
.await
|
||||
.map_err(|e| format!("edge did not re-read the device list: {e}"))
|
||||
if engine.is_none() {
|
||||
pending = Some(
|
||||
"an engine switch is under way; the engine that serves after it is told then"
|
||||
.to_owned(),
|
||||
);
|
||||
} else {
|
||||
Ok(())
|
||||
};
|
||||
result = self.nudge_devices().await;
|
||||
}
|
||||
}
|
||||
if let Ok(mut pr) = self.devices_problem.lock() {
|
||||
*pr = result.as_ref().err().cloned();
|
||||
*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");
|
||||
@@ -223,6 +219,28 @@ impl Control {
|
||||
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";
|
||||
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");
|
||||
Ok(())
|
||||
} else if caddy {
|
||||
self.caddy_reload_checked()
|
||||
.await
|
||||
.map_err(|e| format!("Caddy did not reload the device list: {e}"))
|
||||
} else if self.edge.attached() {
|
||||
self.edge
|
||||
.reload_devices()
|
||||
.await
|
||||
.map_err(|e| format!("edge did not re-read the device list: {e}"))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
async fn reload_serving_engine(&self) {
|
||||
let _engine = self.engine_lock.lock().await;
|
||||
if self.engine_running() == "caddy" {
|
||||
|
||||
@@ -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> {
|
||||
|
||||
Reference in New Issue
Block a user