From 255c55aa3f28c4c13f8e282897778e2404d17541 Mon Sep 17 00:00:00 2001 From: OzzyHelper <346962152+OzzyHelper@users.noreply.github.com> Date: Thu, 19 Nov 2026 16:33:02 +0000 Subject: [PATCH] fix(curio): honor container exit code when waiting on DB setup containers `docker wait` exits 0 and prints the container's exit code on stdout, so checking the command's status always reported success even when `curio config new-cluster` or `curio config create` failed inside the container. Parse the printed code, surface it with container logs, and fail the setup step accordingly. --- src/commands/start/curio/db_setup.rs | 26 +++++++++++----- src/docker/core.rs | 45 ++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 8 deletions(-) diff --git a/src/commands/start/curio/db_setup.rs b/src/commands/start/curio/db_setup.rs index 6c37e47d..50861cfa 100644 --- a/src/commands/start/curio/db_setup.rs +++ b/src/commands/start/curio/db_setup.rs @@ -17,7 +17,7 @@ use crate::docker::command_logger::run_and_log_command; use crate::docker::containers::{ lotus_container_name, postgres_container_name, scylla_container_name, }; -use crate::docker::core::docker_command; +use crate::docker::core::{docker_command, get_container_logs, wait_container_exit_code}; use crate::docker::network::{lotus_network_name, pdp_miner_network_name}; use crate::paths::foc_devnet_bin; use crate::paths::foc_devnet_docker_volumes; @@ -263,15 +263,18 @@ fn create_base_cluster( let _ = docker_command(&["network", "connect", &lotus_network, &container_name]); // Wait for the command to complete - let output = docker_command(&["wait", &container_name])?; + let exit_code = wait_container_exit_code(&container_name)?; + + // Collect logs before removing the container + let logs = get_container_logs(&container_name).unwrap_or_default(); // Clean up container let _ = docker_command(&["rm", "-f", &container_name]); - if !output.status.success() { + if exit_code != 0 { return Err(format!( - "Failed to create base cluster for miner {}: command failed", - miner_id + "Failed to create base cluster for miner {}: container exited with code {}\n{}", + miner_id, exit_code, logs ) .into()); } @@ -376,13 +379,20 @@ fn create_pdp_layer(context: &SetupContext, sp_index: usize) -> Result<(), Box Result> { run_command("docker", args) } +/// Wait for a container to exit and return its exit code. +/// +/// `docker wait` itself exits 0 and prints the container's exit code on +/// stdout, so checking the command's [`std::process::ExitStatus`] would +/// always report success regardless of how the container's command ended. +pub fn wait_container_exit_code(container_name: &str) -> Result> { + let output = docker_command(&["wait", container_name])?; + parse_container_exit_code(&String::from_utf8_lossy(&output.stdout)).map_err(|e| { + format!( + "Failed to read exit code of container {}: {}", + container_name, e + ) + .into() + }) +} + +/// Parse the numeric exit code printed by `docker wait`. +fn parse_container_exit_code(stdout: &str) -> Result { + let trimmed = stdout.trim(); + trimmed.parse::().map_err(|_| { + format!( + "unexpected `docker wait` output (expected an exit code): {:?}", + trimmed + ) + }) +} + /// Get logs from a Docker container. /// /// Collects both stdout and stderr. Go programs (e.g. Curio) @@ -243,3 +270,21 @@ pub fn chown_command(args: &[&str]) -> Result> { command.args(args); command.output().map_err(|e| e.into()) } + +#[cfg(test)] +mod tests { + use super::parse_container_exit_code; + + #[test] + fn parses_docker_wait_exit_codes() { + assert_eq!(parse_container_exit_code("0\n").unwrap(), 0); + assert_eq!(parse_container_exit_code("2\n").unwrap(), 2); + assert_eq!(parse_container_exit_code("137").unwrap(), 137); + } + + #[test] + fn rejects_non_numeric_docker_wait_output() { + assert!(parse_container_exit_code("").is_err()); + assert!(parse_container_exit_code("error: no such container\n").is_err()); + } +}