diff options
| author | aur-build <aur-build@localhost> | 2026-11-19 15:32:44 +0000 |
|---|---|---|
| committer | aur-build <aur-build@localhost> | 2026-11-19 15:32:44 +0000 |
| commit | ec80c312b80ba51271fff0548c6d1e293d373455 (patch) | |
| tree | 41bfc268c01f2a14b88fa90a71f08e855471cedf /src/sandbox/mod.rs | |
| parent | 32eaaeae9e0fe2c2285fb79efa0e579150d8bd83 (diff) | |
| download | aur-build-ec80c312b80ba51271fff0548c6d1e293d373455.tar.gz aur-build-ec80c312b80ba51271fff0548c6d1e293d373455.zip | |
sandbox: the agent listener belongs to the process, not to a build
`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.
Diffstat (limited to 'src/sandbox/mod.rs')
| -rw-r--r-- | src/sandbox/mod.rs | 25 |
1 files changed, 25 insertions, 0 deletions
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<Arc<dyn Sandbox>>; fn status(&self) -> Result<Vec<SandboxInfo>>; } + +/// 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<Arc<dyn SandboxBackend>> { + 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", + ))), + } +} |
