summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/error.rs31
-rw-r--r--src/pipeline/steps.rs33
-rw-r--r--src/sandbox/kata.rs2
3 files changed, 61 insertions, 5 deletions
diff --git a/src/error.rs b/src/error.rs
index cf6e567..342c628 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -30,6 +30,17 @@ pub enum Error {
Invalid(String),
#[error("blocked: {0}")]
Blocked(String),
+ /// The sandbox pool could not fit a lease right now. Not a failure and not
+ /// a retry: the build waits, the same way it waits for a dependency it
+ /// publishes (§10.4). A quota is a fact about capacity, not a bug.
+ #[error("sandbox pool exhausted: {0}")]
+ PoolExhausted(String),
+ /// The world inside the sandbox is not the world the plan approved:
+ /// a pinned dependency did not land, or the closure was incomplete.
+ /// Fail-closed with its own class so a test (and an operator) can tell
+ /// "the sandbox lied" apart from "the sandbox broke".
+ #[error("world mismatch: {0}")]
+ WorldMismatch(String),
/// A failure the outside world caused and a retry may clear: an unreachable
/// upstream, a half-written mirror. Distinct from a deterministic failure,
/// which must never be retried into a different answer (§8.4).
@@ -67,6 +78,19 @@ impl Error {
pub fn transient(s: impl fmt::Display) -> Self {
Error::Transient(s.to_string())
}
+ pub fn pool_exhausted(s: impl fmt::Display) -> Self {
+ Error::PoolExhausted(s.to_string())
+ }
+ pub fn world_mismatch(s: impl fmt::Display) -> Self {
+ Error::WorldMismatch(s.to_string())
+ }
+
+ /// True when the sandbox pool, not the build, is the problem: the build
+ /// should block and wait, not fail and not be retried into a different
+ /// answer.
+ pub fn is_pool_exhausted(&self) -> bool {
+ matches!(self, Error::PoolExhausted(_))
+ }
/// True when a retry could plausibly help (§8.4): an unreachable upstream, a
/// mirror that 5xx'd, a connection that reset.
@@ -79,6 +103,9 @@ impl Error {
pub fn is_transient(&self) -> bool {
match self {
Error::Http(_) | Error::Transient(_) => true,
+ // A quota is capacity, not a hiccup: retrying a build that has no
+ // sandbox just burns attempts. It blocks instead.
+ Error::PoolExhausted(_) | Error::WorldMismatch(_) => false,
Error::Io(e) => matches!(
e.kind(),
std::io::ErrorKind::WouldBlock
@@ -119,5 +146,9 @@ mod tests {
assert!(Error::Http("connection reset".into()).is_transient());
assert!(!Error::invalid("recipe has no pkgbase").is_transient());
assert!(!Error::fail_closed("identity hash moved").is_transient());
+ // A full pool waits; it does not retry. A lying world fails closed.
+ assert!(!Error::pool_exhausted("at quota").is_transient());
+ assert!(!Error::world_mismatch("missing pinned dep").is_transient());
+ assert!(Error::pool_exhausted("at quota").is_pool_exhausted());
}
}
diff --git a/src/pipeline/steps.rs b/src/pipeline/steps.rs
index c989476..59c9a64 100644
--- a/src/pipeline/steps.rs
+++ b/src/pipeline/steps.rs
@@ -130,7 +130,10 @@ fn provision(ctx: &Ctx) -> Result<StepResult> {
if lease.is_empty() {
return Ok(StepResult::Skipped("no of-our-packages dependencies to install".into()));
}
- let sbx = ctx.sandbox()?;
+ let sbx = match sandbox_or_wait(ctx)? {
+ Some(s) => s,
+ None => return Ok(StepResult::Blocked(vec!["sandbox-pool".into()])),
+ };
for e in &lease {
let path = ctx.cfg.store_path(&e.digest);
// The hub hashes what it sends: store corruption is caught here, not
@@ -149,7 +152,10 @@ fn provision(ctx: &Ctx) -> Result<StepResult> {
argv.extend(lease.iter().map(|e| format!("blob:{}", e.digest)));
let out = sbx.run(&Cmd::new(argv), &mut |_| {})?;
if !out.success() {
- return Err(Error::fail_closed(format!(
+ // A refused `-U` is almost always an incomplete closure: the lease set
+ // cannot satisfy itself. Its own error class, because "the sandbox
+ // lied about its world" must not look like "the sandbox broke".
+ return Err(Error::world_mismatch(format!(
"{} -U refused the lease set: {}",
ctx.cfg.pacman_bin,
tail(&out.stderr)
@@ -176,7 +182,7 @@ fn provision(ctx: &Ctx) -> Result<StepResult> {
.collect();
for e in &lease {
if !installed.contains(&(e.name.clone(), e.version.clone())) {
- return Err(Error::fail_closed(format!(
+ return Err(Error::world_mismatch(format!(
"sandbox world is missing {}-{} after installing the lease set",
e.name, e.version
)));
@@ -191,6 +197,22 @@ fn provision(ctx: &Ctx) -> Result<StepResult> {
Ok(StepResult::Done(Some(crate::hash::canonical_json(&world)?)))
}
+/// Lease a sandbox for a step, or report that the pool cannot fit one right
+/// now. A full pool is not a broken build: the build blocks and waits, the
+/// same way it waits for a dependency it publishes (§10.4).
+fn sandbox_or_wait(
+ ctx: &Ctx,
+) -> Result<Option<std::sync::Arc<dyn crate::sandbox::Sandbox>>> {
+ match ctx.sandbox() {
+ Ok(s) => Ok(Some(s)),
+ Err(e) if e.is_pool_exhausted() => {
+ ctx.log_line(" blocked: no sandbox available in the pool");
+ Ok(None)
+ }
+ Err(e) => Err(e),
+ }
+}
+
/// One pinned entry of the lease manifest.
#[derive(Debug, Clone)]
struct LeasePkg {
@@ -307,6 +329,10 @@ fn pkgver(ctx: &Ctx) -> Result<StepResult> {
/// ingest signs hub-side.
fn build(ctx: &Ctx) -> Result<StepResult> {
let argv = vec![ctx.cfg.makepkg_bin.clone(), "-c".into(), "-f".into()];
+ let sbx = match sandbox_or_wait(ctx)? {
+ Some(s) => s,
+ None => return Ok(StepResult::Blocked(vec!["sandbox-pool".into()])),
+ };
// Capture the child's output into the build log regardless of outcome —
// the sandbox streams it here as it arrives, and the SSE tail reads the
// same file.
@@ -320,7 +346,6 @@ fn build(ctx: &Ctx) -> Result<StepResult> {
let _ = f.write_all(bytes);
}
};
- let sbx = ctx.sandbox()?;
let out = sbx.run(&Cmd::new(argv).in_dir(&ctx.srcdir), &mut on_log)?;
drop(on_log); // closes the log file before the outcome is recorded
if !out.success() {
diff --git a/src/sandbox/kata.rs b/src/sandbox/kata.rs
index 7a83f89..9592dca 100644
--- a/src/sandbox/kata.rs
+++ b/src/sandbox/kata.rs
@@ -324,7 +324,7 @@ impl SandboxBackend for KataBackend {
Err(_) => {
self.pending.lock().unwrap().remove(&id);
let _ = self.provisioner.reclaim(&id);
- return Err(Error::other(format!(
+ return Err(Error::pool_exhausted(format!(
"sandbox {id} for profile {} never dialed in within its TTL",
spec.profile
)));