fix: pgtest left an anonymous volume behind on every run #175

Merged
sulthan merged 1 commits from fix/pgtest-volume-leak into main 2026-08-23 13:14:50 +07:00
Owner

Problem

go test ./... leaked one Docker volume per test package. pgtest.Main tore its throwaway container down with docker rm -f — no -v. The postgres:17-alpine image declares a VOLUME for /var/lib/postgresql/data, and an explicit rm without -v orphans that anonymous volume even though the container was created with --rm.

Found in passing: a 13-hour-old orphaned pgtest container (AutoRemove, fsync=off, one mount) still running from a killed test binary — the same leak's other half. Removed on the dev machine.

Change

  • backend/internal/pgtest/pgtest.go: -v on all three docker rm -f teardown sites (Main's defer, and both error paths in start).
  • AGENTS.md: cleanup expectation under Commands — docker compose down -v for a stack, docker rm -f -v for a hand-run container, then check docker volume ls and docker system df. Explicitly out of bounds: removing the user's postgres-data volume, or a blanket docker system prune of their images and build cache.

Verification

docker volume ls snapshot diffed across a real ./internal/store run: no new volumes, docker system df reports 0 local volumes.

## Problem `go test ./...` leaked one Docker volume per test package. `pgtest.Main` tore its throwaway container down with `docker rm -f` — no `-v`. The `postgres:17-alpine` image declares a `VOLUME` for `/var/lib/postgresql/data`, and an explicit `rm` without `-v` orphans that anonymous volume even though the container was created with `--rm`. Found in passing: a 13-hour-old orphaned pgtest container (AutoRemove, `fsync=off`, one mount) still running from a killed test binary — the same leak's other half. Removed on the dev machine. ## Change - `backend/internal/pgtest/pgtest.go`: `-v` on all three `docker rm -f` teardown sites (`Main`'s defer, and both error paths in `start`). - `AGENTS.md`: cleanup expectation under Commands — `docker compose down -v` for a stack, `docker rm -f -v` for a hand-run container, then check `docker volume ls` and `docker system df`. Explicitly out of bounds: removing the user's `postgres-data` volume, or a blanket `docker system prune` of their images and build cache. ## Verification `docker volume ls` snapshot diffed across a real `./internal/store` run: no new volumes, `docker system df` reports 0 local volumes.
sulthan added 1 commit 2026-08-23 13:07:16 +07:00
The postgres image declares a VOLUME, so tearing the container down with
`docker rm -f` (no -v) orphaned its anonymous data volume each time the
test binary ran. Add -v to all three teardown sites, and state the
cleanup expectation in AGENTS.md so a killed run gets swept by hand.
sulthan merged commit e1ba7fdabb into main 2026-08-23 13:14:50 +07:00
Sign in to join this conversation.