From 586613e1d03781f808e7fcd4093cbf270b155fff Mon Sep 17 00:00:00 2001 From: Stephan Boyer Date: Sun, 19 Oct 2025 23:06:53 -0700 Subject: [PATCH] Add some comments and refactor some code related to the recent crash loop fix --- CHANGELOG.md | 5 +++++ Cargo.lock | 2 +- Cargo.toml | 2 +- src/run.rs | 53 ++++++++++++++++++++++++++++++++-------------------- 4 files changed, 40 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d11993b..9d160e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.25.1] - 2025-10-19 + +### Fixed +- Docuum no longer enters a crash loop when there are containers stuck in the `removing` state. Thanks to Addison Kimball for reporting this issue, and thanks to Farrukh Taqveem for investigating and fixing it. + ## [0.25.0] - 2024-05-02 ### Added diff --git a/Cargo.lock b/Cargo.lock index 1a62b77..b91c358 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -201,7 +201,7 @@ dependencies = [ [[package]] name = "docuum" -version = "0.25.0" +version = "0.25.1" dependencies = [ "atty", "byte-unit", diff --git a/Cargo.toml b/Cargo.toml index d677931..ff08a4a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "docuum" -version = "0.25.0" +version = "0.25.1" authors = ["Stephan Boyer "] edition = "2024" description = "LRU eviction of Docker images." diff --git a/src/run.rs b/src/run.rs index 41c9012..02d92bc 100644 --- a/src/run.rs +++ b/src/run.rs @@ -29,6 +29,22 @@ use { // maximum number of container IDs to query at once. const CONTAINER_IDS_CHUNK_SIZE: usize = 100; +// [tag:container_status_removing] The `docker container inspect` command seems to fail on +// containers with this status. Source: https://github.com/stepchowfun/docuum/issues/237 +const CONTAINER_STATUS_REMOVING: &str = "removing"; + +// These are all the possible statuses returned from `docker container ls`. Source: +// https://docs.docker.com/reference/cli/docker/container/ls/#status +const CONTAINER_STATUSES: [&str; 7] = [ + "created", + "dead", + "exited", + "paused", + "restarting", + "running", + CONTAINER_STATUS_REMOVING, +]; + // A Docker event (a line of output from `docker events --format '{{json .}}'`) #[derive(Deserialize, Serialize, Debug)] struct Event { @@ -218,26 +234,23 @@ fn list_image_records(state: &State) -> io::Result> fn image_ids_in_use() -> io::Result> { // Query Docker for all the container IDs. let container_ids_output = Command::new("docker") - .args([ - "container", - "ls", - "--all", - "--filter", - "status=created", - "--filter", - "status=restarting", - "--filter", - "status=running", - "--filter", - "status=paused", - "--filter", - "status=exited", - "--filter", - "status=dead", - "--no-trunc", - "--format", - "{{.ID}}", - ]) + .args( + ["container", "ls", "--all"] + .into_iter() + .map(std::string::ToString::to_string) + .chain( + CONTAINER_STATUSES + .iter() + .filter(|&&status| status != CONTAINER_STATUS_REMOVING) + .flat_map(|&status| [String::from("--filter"), format!("status={status}")]), + ) + .chain( + ["--no-trunc", "--format", "{{.ID}}"] + .into_iter() + .map(std::string::ToString::to_string), + ) + .collect::>(), + ) .stderr(Stdio::inherit()) .output()?;