From ec80c312b80ba51271fff0548c6d1e293d373455 Mon Sep 17 00:00:00 2001 From: aur-build Date: Thu, 19 Nov 2026 15:32:44 +0000 Subject: sandbox: the agent listener belongs to the process, not to a build MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `Ctx::new` constructed a backend for every build, and constructing a remote backend bound the agent listener. With a fixed `listen` — which is what any real deployment configures, since the operator has to tell the agents where to dial — the second concurrent build died of EADDRINUSE. A build failing for a reason that had nothing to do with its package is the worst kind of flake: it looks like the package's fault. `RemoteBackend::bind` now shares one bound listener per `(address, token)` for the life of the process, and hands each backend a clone of the dial-in queue. That is also what `remote` already meant: an agent dials in when the operator boots one and whichever build is waiting takes it. The token is part of the key deliberately — two tokens cannot share a listener, and quietly reusing the first one's would be a fail-open surprise, so the second bind is attempted and fails loudly instead. Backend construction moved out of `Ctx` into `sandbox::backend_for`, so "which backend" has exactly one answer and the validation guard travels with it. Tests cover the shared listener, the shared queue (the *second* backend takes the dial-in), the two-token refusal, and two concurrent `Ctx`es on one address — with an assertion that a raw second bind still fails, so the test cannot rot into proving nothing. --- src/sandbox/mod.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/sandbox/mod.rs') diff --git a/src/sandbox/mod.rs b/src/sandbox/mod.rs index b20788d..cdbfa02 100644 --- a/src/sandbox/mod.rs +++ b/src/sandbox/mod.rs @@ -29,6 +29,7 @@ use std::path::PathBuf; use std::sync::Arc; use std::time::Duration; +use crate::config::Config; use crate::error::Result; pub mod agent; @@ -138,3 +139,27 @@ pub trait SandboxBackend: Send + Sync { fn acquire(&self, spec: &SandboxSpec) -> Result>; fn status(&self) -> Result>; } + +/// Turn a configuration into the backend it names — the only place that does, +/// so "which backend" has exactly one answer. +/// +/// `Config::validate` runs here as well as at startup: a guard that only exists +/// in the CLI is a guard a test, a tool, or a future daemon can walk past. +/// And an unknown or unwired kind is an error, never a fallthrough — a build +/// configured for a Kata VM that quietly ran as the hub's own user is the +/// failure this function used to have. +pub fn backend_for(cfg: &Config) -> Result> { + cfg.validate()?; + match &cfg.sandbox { + crate::config::Sandbox::Loopback => { + Ok(Arc::new(loopback::LoopbackBackend::new(cfg))) + } + crate::config::Sandbox::Remote { listen, token, .. } => { + Ok(Arc::new(remote::RemoteBackend::bind(cfg, listen, token)?)) + } + crate::config::Sandbox::AgentSandbox { .. } => Err(crate::error::Error::invalid(concat!( + "sandbox kind \"agent-sandbox\" is not wired up yet; refusing to run this build ", + "on a backend it was not configured for", + ))), + } +} -- cgit v1.2.3