Files
leleka/control-plane/src/engine_probe.rs
T

46 lines
1.8 KiB
Rust

//! Explicit loader probe for an operator-trusted engine with a side-effect-free --help.
use std::{ffi::OsStr, process::Stdio, time::Duration};
use tokio::{process::Command, time::timeout};
fn spawn_help(executable: &OsStr) -> Result<tokio::process::Child, crate::BoxError> {
Ok(Command::new(executable)
.arg("--help")
.env("CUDA_VISIBLE_DEVICES", "")
.stdin(Stdio::null())
.stdout(Stdio::null())
.stderr(Stdio::null())
.kill_on_drop(true)
.spawn()
.map_err(|_| {
"engine loader probe could not start; check executable permissions, ELF architecture and \
loader/shared-library dependencies"
})?)
}
pub async fn check(executable: &OsStr) -> Result<(), crate::BoxError> {
// Keep the memfd alive until the help process has exited. Serving may have already resolved the payload and keeps
// its own lifetime guard.
let embedded = crate::embedded_engine::resolve(executable)?;
let executable = embedded.as_ref().map_or(executable, |e| e.executable.as_os_str());
let mut child = spawn_help(executable)?;
match timeout(Duration::from_secs(10), child.wait()).await {
Ok(Ok(status)) if status.success() => Ok(()),
Ok(Ok(status)) => Err(format!(
"engine --help probe failed ({status}); check loader/shared-library dependencies \
or use a profile with a working --help command"
)
.into()),
failure => {
let _ = child.kill().await;
Err(match failure {
Err(_) => {
"engine --help probe timed out after 10 seconds; check the selected engine before preparing \
the model"
}
_ => "engine --help probe could not be collected; check the selected engine",
}
.into())
}
}
}