Skip to content

deps: pin testcontainers-go to the fix for a reaper being removed - #715

Merged
Kiran01bm merged 2 commits into
mainfrom
kiran01bm/deflake-reaper-removing-race
Dec 3, 2026
Merged

Kiran01bm merged 2 commits into
mainfrom
kiran01bm/deflake-reaper-removing-race

Conversation

@Kiran01bm

@Kiran01bm Kiran01bm commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

Pins testcontainers-go to the upstream commit that recovers from a reaper container being removed, which fails a test package's first container start in CI.

Why

pg-sprite's integration tests start PostgreSQL and PgBouncer in Docker through testcontainers-go. All the test binaries of one go test ./... run share a single cleanup container, the reaper, which shuts itself down once no test has used it for a while. When a package starts its first container at the moment that reaper is shutting down, testcontainers-go gives up instead of starting a new one, so that package's first test fails. CI runs packages in roughly the same order, so the same test kept failing: TestConnectReplicationAsksForWarningsThroughPgBouncer in pkg/dbconn, in 4 of the last 40 failed CI runs, one of them on main.

What

  • github.com/testcontainers/testcontainers-go and modules/postgres move from v0.45.0 to v0.45.1-0.20261109125418-f31e98d4ee9b: testcontainers-go#3868, "recover from stopped, orphaned and unready reapers". No release carries it yet; a comment above the two lines in go.mod says to move both to the first tagged release after v0.45.0.
  • The same commit makes the reaper handshake strict: Reaper.Connect now returns an error when Ryuk does not acknowledge within 5 s, where v0.45.0 only logged it. A test whose first container start now fails with a reaper handshake: error is meeting that check, typically a slow or overloaded Docker host, not a pg-sprite regression.
  • docs/tcb-model.md no longer says pgregory.net/rapid is in the module graph; go mod tidy drops its stale go.sum lines, and nothing imports it.
  • No other module in go.mod moves. The vulnerability gate passes; its one unreachable module-level finding (golang.org/x/crypto v0.58.0) is already on main.
  • Reproduced locally: two test packages in one go test run, the second starting its first container while the first's reaper idles out (TESTCONTAINERS_RYUK_RECONNECTION_TIMEOUT=1s, the second package waiting 350 to 550 ms). On v0.45.0, 5 of 15 runs failed with the CI error. With the pin, 0 of 30 failed, and the second package created a fresh reaper instead of waiting on the one being removed.

Before / after

The CI job's pkg/dbconn binary starts its first container, for the PgBouncer test, while the reaper another package started is being removed.

Before (v0.45.0)
  pkg/dbconn   look up the session's reaper   ──▶ found, status "removing"
               wait for it to be ready        ──▶ "unexpected container status \"removing\""
               treated as permanent           ──▶ create the pooler test network fails
  result       TestConnectReplicationAsksForWarningsThroughPgBouncer FAIL

After (pinned to the upstream fix)
  pkg/dbconn   look up the session's reaper   ──▶ found, not running
               remove it as stale, report not found
               create a new reaper            ──▶ create the pooler test network succeeds
  result       the test runs

The test binaries of one go test run share a reaper, which exits after
its idle timeout. A binary that looks it up while it is being removed
fails its first container start with "unexpected container status
removing" instead of creating a new reaper. testcontainers-go fixed this
after v0.45.0 and has not tagged a release with it yet.
@Kiran01bm
Kiran01bm marked this pull request as ready for review December 3, 2026 05:27
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-12-03T05:27:32.122725Z
We couldn’t complete this review. Comment @codex review to try again.
db554a8 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@aparajon

aparajon commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

🤖 Review 1/2 (correctness) of db554a8: 0 blocking, 2 non-blocking.

Inspected the whole change at db554a827594b32c8775305a353fd486480de50b: go.mod (+2/-2) and go.sum (+4/-10), against the upstream commit the pin names and against what pg-sprite's build and tests actually import. CI at the time of posting: 11 checks green (build, lint, unit tests, smoke test, aws-boundary, Vulnerability Scan, Semgrep, zizmor, DCO) and 6 still running (the PostgreSQL 14 to 17 legs, test (PostgreSQL 18, other packages) and Supabase compatibility). The pkg/dbconn PgBouncer test runs in the container legs, so its result at this head was not in yet; the fix claim rests on the upstream change and the PR's local reproduction, not on a CI result I saw.

The PR moves testcontainers-go and testcontainers-go/modules/postgres from v0.45.0 to v0.45.1-0.20261109125418-f31e98d4ee9b. It is correct and does target the failure it names. No production file changes, so no docs/invariants.md entry is touched.

Does the pin carry the reaper fix?

Yes, checked through the GitHub API on testcontainers/testcontainers-go:

  • f31e98d4ee9b8432433171505b6652a42551bf63 is the merge commit of testcontainers-go#3868, "fix(reaper): recover from stopped, orphaned and unready reapers", merged to main on 2026-11-09 12:54:19 UTC. The pseudo-version timestamp 20261109125418 matches the commit time (12:54:18) and the 12-character hash is that commit's prefix.
  • It is 5 commits ahead of the v0.45.0 tag (published 2026-11-05) and 0 behind, so v0.45.1-0 is the right base. The latest release is still v0.45.0, so no tag carries the fix yet.
  • The change to reaper.go treats a reaper whose state is not running as stale and recreates it. Its new test table names removing beside exited and dead as stale states, which is the exact unexpected container status "removing" failure seen in TestConnectReplicationAsksForWarningsThroughPgBouncer on verdict: name what a stopped run leaves in a typed standing_run field #708 and executor: give a partitioned table to attach the parent's indexes #713. A reaper that has been created but never started past a grace period is replaced too, and readiness becomes a handshake with Ryuk instead of a status poll.
  • The five commits between the tag and the pin are the reaper fix, a DynamoDB WithInMemory option, a CI matrix tweak, a Redis docs edit, and the version bump. Only the reaper commit and the small docker.go image-substitutor refactor it shipped with touch code pg-sprite compiles; modules/postgres is unchanged in the range.

go.mod and go.sum

  • Both modules are moved to the same pseudo-version, as they must be. modules/postgres at the pin still says require github.com/testcontainers/testcontainers-go v0.45.0 with a replace ... => ../..; a replace in a dependency is ignored, and the root module's higher requirement wins by minimum version selection, so the postgres module builds against the fixed core.
  • The two new /go.mod hashes in go.sum (VMJZ7M+qh... for core, v59yuxG94... for postgres) are byte-for-byte the v0.45.0 ones, which is right: neither module's go.mod changed in the range. Each pin has a fresh h1: zip hash.
  • The 12 removed lines are all go.sum/go.mod lines for versions no longer selected or used: the 4 v0.45.0 testcontainers lines, the moby/moby/api v1.56.1 and moby/moby/client v0.6.2 pairs (go.mod already requires v1.57.0 and v0.6.3), and pgregory.net/rapid v1.2.0. No replace or exclude directive is removed, and nothing in *.go imports rapid (finding 2 in the next comment covers a doc that says otherwise). build, lint, unit tests (no Docker; docs guards), smoke test and Vulnerability Scan all passed at this head, and those jobs run with the default read-only module mode, which fails on a missing go.sum entry.

Non-blocking

  1. A commit pin has no marker in go.mod saying it is temporary. The PR body says "the next tag replaces this pin", but a pseudo-version in a require block reads the same as a deliberate choice a year from now, and nothing will prompt the swap once a release lands. A one-line comment above the two lines (// unreleased reaper fix, testcontainers-go#3868; move to the next release) keeps the intent next to the pin, and a reviewer who later sees v0.45.1-0.2026... knows what to look for.
  2. One green run cannot show the flake is gone, and the pin changes Reaper.Connect's contract for every test in the repo. The failure hit about 4 of 40 runs, so a single passing CI run is weak evidence; the 0 of 30 against 5 of 15 local reproduction in the PR body is the real proof and is a sound design (two packages, one reaper idling out). Separately, the upstream commit message says Reaper.Connect now returns an error when Ryuk does not acknowledge, where before it only logged. pg-sprite's container tests all go through the reaper, so an environment with a Ryuk that is slow to answer (a loaded CI runner, a rootless or Podman developer machine) now fails the test that starts the first container instead of continuing with a warning. That is the stricter, safer behavior and matches the failure the PR is fixing, so it is not a reason to hold the pin; it is worth a sentence in the PR body so a contributor who sees a new reaper handshake error knows where it comes from.

Verified

  • Read the upstream merge commit's file list (docker.go, reaper.go, testing.go, tests, modules/compose test) and its reaper stale-state table, and confirmed the commit is an ancestor-ahead of v0.45.0 through the compare API.
  • Read go.mod at the head: both testcontainers lines are the only version change, moby/moby/api v1.57.0 and client v0.6.3 are unchanged, and no replace block exists before or after.
  • Read both upstream go.mod files at the pin: the core module's requirement set is identical to v0.45.0's, so the pin pulls in no new transitive module.
  • Ran nothing locally: this review touched no checkout, and the container-backed legs need Docker.
Mutant Caught by
a missing go.sum hash for either pin build, lint, unit tests (read-only module mode)
pin does not contain the reaper fix the PgBouncer test going red in the container legs (see CI above)

This review was generated by Claude Code (claude-sonnet-5-5).

@aparajon

aparajon commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

🤖 Review 2/2 (OSS adoption and integration) of db554a8: 0 blocking, 2 non-blocking.

Read the change from two seats: a contributor who runs make test against Docker and has been hitting the intermittent TestConnectReplicationAsksForWarningsThroughPgBouncer failure, and a downstream importer of pg-sprite. The importer side is a non-issue: testcontainers-go is test-only here, the pin lives in pg-sprite's own go.mod, and a module that imports pg-sprite packages does not inherit a test dependency's version (Go's graph pruning keeps it out of their build list unless they import the same packages).

Non-blocking

  1. docs/tcb-model.md still says pgregory.net/rapid is "already in our module graph via pgx", and this PR removes its go.sum lines. The sentence is in the verification-ladder section of docs/tcb-model.md ("Property-based tests (pgregory.net/rapid — already in our module graph via pgx)"). It was not true before the PR either: go.mod has no rapid requirement and pgx/v5 v5.13.0's own go.mod does not list it, so the old go.sum lines were stale. The tidy that this PR carries makes that visible. A contributor who follows the doc and writes a rapid property test will hit a missing module and need a go get. Rewording to "add pgregory.net/rapid when the first property test lands" keeps the doc true. It is unrelated to the pin's purpose, so a follow-up is fine.
  2. A contributor who sees the old failure again has no pointer to what the pin was for. The PR body is a good record of the cause (a shared reaper idling out while the next package starts its first container), but the repository carries none of it: no comment beside the go.mod lines, and no note in the contributing docs for container-test flakes. A short comment above the two go.mod lines naming testcontainers-go#3868 and the symptom string (unexpected container status "removing") means someone who greps the error message from a red run finds the explanation, and finds the line to revisit when a tagged release carries the fix.

What reads well for adopters

  • The PR body states the cause in terms a contributor can verify: the shared reaper, the 1-second reconnection timeout used to reproduce, and the exact error. The before/after shows the same pkg/dbconn start under each version with the failing step named.
  • The change is as small as a dependency fix can be: two lines in go.mod, no code, no workflow edit, no new module in the graph. The container legs need no change to pick it up.
  • It keeps testcontainers-go and modules/postgres on one version, so the two cannot drift apart across a later bump.
  • The test is untouched and not retried or skipped: the fix is made upstream, where every user of the library gets it, rather than papered over in pg-sprite.

This review was generated by Claude Code (claude-sonnet-5-5).

@aparajon aparajon left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Stamping with comments: 0 blocking, 4 non-blocking (see the review comments above).

This stamp was left by Claude Code (claude-sonnet-5-5).

@Kiran01bm

Copy link
Copy Markdown
Collaborator Author

🤖 Adversarial review response — created by Kiran's code review agent (Amp, claude-opus-5-5) — pull/715, follow-up commit

All 4 non-blocking findings fixed: the pin now says in go.mod what it is for and when to move it, and the PR description names the stricter reaper handshake.

# Finding Status Explanation
C1-F1 The commit pin has no marker in go.mod saying it is temporary fixed A comment above the two lines says they are pinned to an untagged commit and to move both to the first tagged release after v0.45.0; go mod tidy keeps it.
C2-F2 A contributor who sees the old failure again has no pointer to the pin fixed The same comment carries the symptom, unexpected container status "removing", so grepping a red run's error finds it. The upstream PR number stays in the PR description, since the repo keeps PR references out of code comments.
C1-F2 One green run is weak evidence, and the pin makes Reaper.Connect strict fixed The PR description now says Reaper.Connect returns the handshake error after 5 s where v0.45.0 only logged it (confirmed in the pinned reaper.go), and what a new handshake: failure means. The flake evidence is the 5 of 15 vs 0 of 30 reproduction, as the finding notes; every container leg is also green at this head.
C2-F1 docs/tcb-model.md says pgregory.net/rapid is in the module graph fixed Reworded to say it is added to go.mod with the first property test.

No action: the "Does the pin carry the reaper fix?", "go.mod and go.sum" and "Verified" sections of review comment 7368866201, the "What reads well for adopters" section of review comment 7368867502, approving review 6164220335, and Codex comments 7368762330 and 7368763061, which hit a usage limit before reviewing.

Source: block/pg-sprite#715, review comments 7368866201 and 7368867502 and review 6164220335 at head db554a82. Fixes are in the follow-up commit.

@Kiran01bm
Kiran01bm enabled auto-merge (squash) December 3, 2026 06:15
@Kiran01bm
Kiran01bm merged commit 8c1b18a into main Dec 3, 2026
18 checks passed
@Kiran01bm
Kiran01bm deleted the kiran01bm/deflake-reaper-removing-race branch December 3, 2026 06:27
Kiran01bm added a commit that referenced this pull request Dec 4, 2026
…timeout-every-step

* origin/main: (38 commits)
  feat(schemadiff): report an invalid index's size on disk (#724)
  docs(planner): say the catalog-only proof covers the statement as submitted (#725)
  schemadiff: show a generated expression change as a drop and re-add before PostgreSQL 17 (#723)
  statement: admit foreign keys in a row security file (#722)
  schemadiff: name the sequence and types a serial sequence type refusal compared (#719)
  feat(statement): find the orphan rows of a validated foreign key outside public (#721)
  statement: name the policies a row security file declares (#720)
  schemadiff: name the constraint that keeps a renamed rule (#718)
  cli: report an unreadable write fence as unknown in status (#690)
  executor: refuse a DETACH ... FINALIZE step in RunSequence (#689)
  schemachange: wait outside the lock queue before a discard's fence drop (#688)
  docs: point the remote apply ID sources at SchemaBot's design folder (#707)
  dbconn: give a lock held elsewhere at Confirm its own type (#686)
  deps: pin testcontainers-go to the fix for a reaper being removed (#715)
  executor: report a native step's row fault as data-fault (#685)
  migrate: run a CREATE TABLE ... PARTITION OF as the online create of a partition (#684)
  dbconn: qualify the table lock's pg_locks reads (#683)
  preflight: ask a resume holding its own slot for no free slot (#682)
  executor: remove a failed unique partitioned build's parent index (#704)
  migrate: drop an unfinished partitioned index build's parent index (#705)
  ...
Kiran01bm added a commit that referenced this pull request Dec 4, 2026
Picks up the testcontainers-go pin (#715) that recreates a reaper being
removed, which failed this branch's PostgreSQL 18 job.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants