fix: run containers with --rm to avoid lingering exited containers#348
Open
gtsiolis wants to merge 2 commits into
Open
fix: run containers with --rm to avoid lingering exited containers#348gtsiolis wants to merge 2 commits into
gtsiolis wants to merge 2 commits into
Conversation
27f0184 to
add38b3
Compare
Containers were created without --rm (AutoRemove=false), leaving stopped containers in Exited state indefinitely on mixed hosts. Set AutoRemove on the HostConfig to match the Python CLI lifecycle. Generated with [Linear](https://linear.app/localstack/issue/DEVX-943/run-cli-containers-with-rm-to-avoid-lingering-exited-containers#agent-session-0a1c1991) Co-authored-by: linear-code[bot] <222613912+linear-code[bot]@users.noreply.github.com>
Running containers with --rm (AutoRemove) introduced two regressions that broke `lstk restart` / start-over-existing and erased crash diagnostics: 1. Removal race. With --rm, stopping a container kicks off an asynchronous removal. The start flow's "remove existing container before create" (pullImages -> rt.Remove) then hit "removal of container ... is already in progress" (a conflict, not not-found) and failed; even when tolerated, the name could still be taken when ContainerCreate ran next. DockerRuntime.Remove now tolerates the conflict and waits until the container is actually gone before returning, so the subsequent create does not race the in-flight removal. This fixes TestRestartCommandSucceeds, TestRestartCommandPersistFlagSetsPersistenceEnv, and TestSAME2EDeployCustomAccount. 2. Lost startup logs. awaitStartup fetched the container's logs to explain a crash, but --rm removed the container before the poll detected the exit, so the fetch returned nothing. The start flow now follows the container's logs into a bounded buffer while it runs, so the tail survives auto-removal and still explains a failed start. Also make the custom-image integration test's post-hoc container inspect best-effort, since the stub container is auto-removed the instant it exits; the "Using local image" output remains the authoritative signal.
add38b3 to
a2ebb89
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Containers were created without
--rm(AutoRemove=false), so stopped containers stayed inExitedstate and could linger indefinitely on mixed hosts. This setsAutoRemoveon theHostConfiginDockerRuntime.Start, the Docker SDK equivalent of--rm, matching the Python CLI lifecycle.The existing
Stopalready tolerates the container being gone (it ignores conflict/not-found fromContainerRemove), so it stays correct now that Docker may auto-remove the container on stop.Adds an
auto removeassertion toTestStartCommandSetsUpContainerCorrectlyto guard against regression.