[control] Start and resolver (QC nits): the live tree goes through the same rules as an apply before control writes it to the engines, and a guard frees an edge name lookup's entry and thread on every way out, a panic included
This commit is contained in:
@@ -678,6 +678,25 @@ impl Control {
|
|||||||
errors: fe,
|
errors: fe,
|
||||||
}
|
}
|
||||||
})?;
|
})?;
|
||||||
|
self.policy(&model)?;
|
||||||
|
Ok(Plan {
|
||||||
|
kind,
|
||||||
|
verb: host_verb(kind),
|
||||||
|
summary,
|
||||||
|
hosts,
|
||||||
|
target,
|
||||||
|
model,
|
||||||
|
attempted,
|
||||||
|
undo_of,
|
||||||
|
restore_of,
|
||||||
|
effect,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// What control allows beyond core's schema, for every tree it applies and for the live
|
||||||
|
/// tree at start: the UI proof only on the [ui] host, a socket upstream only there and only
|
||||||
|
/// to control's own UI socket.
|
||||||
|
fn policy(&self, model: &ianitor_core::Model) -> Result<(), Fail> {
|
||||||
// The UI proof belongs to the [ui] host only (core already demands forward-auth for it).
|
// The UI proof belongs to the [ui] host only (core already demands forward-auth for it).
|
||||||
let ui_host = self.cfg.ui.as_ref().and_then(|u| u.hostname.as_deref());
|
let ui_host = self.cfg.ui.as_ref().and_then(|u| u.hostname.as_deref());
|
||||||
// A socket upstream likewise: only the [ui] host, and only control's own UI socket (a
|
// A socket upstream likewise: only the [ui] host, and only control's own UI socket (a
|
||||||
@@ -738,18 +757,7 @@ impl Control {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(Plan {
|
Ok(())
|
||||||
kind,
|
|
||||||
verb: host_verb(kind),
|
|
||||||
summary,
|
|
||||||
hosts,
|
|
||||||
target,
|
|
||||||
model,
|
|
||||||
attempted,
|
|
||||||
undo_of,
|
|
||||||
restore_of,
|
|
||||||
effect,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compile(&self, model: &ianitor_core::Model) -> Result<(String, String), Fail> {
|
fn compile(&self, model: &ianitor_core::Model) -> Result<(String, String), Fail> {
|
||||||
@@ -1794,6 +1802,18 @@ impl Control {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
// A tree kept under an earlier control.toml may break today's rules (a changed [ui]
|
||||||
|
// hostname or socket): it is not written to the engines, and the reason is logged; the
|
||||||
|
// engines keep the last files written. The next apply is refused for the same reason.
|
||||||
|
if let Err(f) = self.policy(&model) {
|
||||||
|
let detail = f
|
||||||
|
.errors
|
||||||
|
.first()
|
||||||
|
.map(|e| e.message.clone())
|
||||||
|
.unwrap_or_else(|| f.reason.message.clone());
|
||||||
|
log::error!(target: "ianitor::control", "the routes repository breaks control's rules ({detail}); the engines keep the files they have");
|
||||||
|
return;
|
||||||
|
}
|
||||||
let Ok((edge_text, caddy_text)) = self.compile(&model) else {
|
let Ok((edge_text, caddy_text)) = self.compile(&model) else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -130,12 +130,28 @@ impl Resolver {
|
|||||||
.spawn({
|
.spawn({
|
||||||
let key = key.clone();
|
let key = key.clone();
|
||||||
move || {
|
move || {
|
||||||
|
// Removes the name's entry and frees the thread's place on every way out, a
|
||||||
|
// panic in the resolver included: the next request for the name starts a
|
||||||
|
// new lookup instead of joining a dead one.
|
||||||
|
struct Done {
|
||||||
|
inflight: Arc<Inflight>,
|
||||||
|
key: (String, u16),
|
||||||
|
_permit: OwnedSemaphorePermit,
|
||||||
|
}
|
||||||
|
impl Drop for Done {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
lock(&self.inflight).remove(&self.key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let _done = Done {
|
||||||
|
inflight,
|
||||||
|
key: key.clone(),
|
||||||
|
_permit: permit,
|
||||||
|
};
|
||||||
let answer = lookup(&key.0, key.1)
|
let answer = lookup(&key.0, key.1)
|
||||||
.map(Arc::new)
|
.map(Arc::new)
|
||||||
.map_err(|e| (e.kind(), e.to_string()));
|
.map_err(|e| (e.kind(), e.to_string()));
|
||||||
let _ = tx.send(Some(answer));
|
let _ = tx.send(Some(answer));
|
||||||
lock(&inflight).remove(&key);
|
|
||||||
drop(permit);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if let Err(e) = spawned {
|
if let Err(e) = spawned {
|
||||||
|
|||||||
Reference in New Issue
Block a user