[control] Fix round 3: revocations never wait for an apply (files and edge at once; under Caddy the reload is left to the end of a running trial), confirmed before the deadline is claimed, the guard marks a trial expired only after a verified load and retries, caddy-revert clears a stale deadline when Pingora serves

This commit is contained in:
2026-11-08 12:28:35 +01:00
parent 09b8313a04
commit 4d87537a76
5 changed files with 173 additions and 59 deletions
+24 -5
View File
@@ -164,12 +164,16 @@ impl Control {
}
/// The device files changed (issue or revoke): rewrite them and tell the engine at once.
///
/// It never waits for an apply (fix round 3): the files go to disk at once and edge is told
/// at once, also during a watch (edge's trial reads the same files). Only when Caddy serves
/// *and* a trial is out is the Caddy reload left to the end of that apply: a reload now
/// would drop the trial, and the end of every Caddy trial loads caddy.json again (promote,
/// revert, caddy-guard, caddy-revert), which reads the new files. During an engine switch
/// (engine lock busy for more than a second) the engine being started reads them anyway.
pub async fn devices_changed(&self) -> Result<(), String> {
let Some(p) = &self.pki else { return Ok(()) };
// Behind a running apply (QC round 2, M2): a reload during a Caddy trial's watch would
// drop the trial; afterwards it loads whatever is current.
let _apply = self.apply_lock.lock().await;
let _engine = self.engine_lock.lock().await;
let _files = self.devices_lock.lock().await;
let t = now();
let mut result = Ok(());
for dir in self.cert_dirs() {
@@ -180,9 +184,24 @@ impl Control {
));
}
}
// The engine lock is held for long only by a switch; an apply holds it for a moment
// (loading a trial, or from the claim to the promoted reload), so then this waits.
let engine =
match tokio::time::timeout(Duration::from_secs(1), self.engine_lock.lock()).await {
Ok(g) => Some(g),
Err(_) if self.engine_state().state == "switching" => None,
Err(_) => Some(self.engine_lock.lock().await),
};
// Tell the serving engine every time, changed or not: a repeated Revoke nudges again.
if result.is_ok() {
result = if self.engine_running() == "caddy" {
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}"))