Skip to content

Start Redpanda only after its config is in place - #1483

Open
alpcanaydin wants to merge 2 commits into
testcontainers:mainfrom
alpcanaydin:claude/fix-redpanda-config-race
Open

alpcanaydin wants to merge 2 commits into
testcontainers:mainfrom
alpcanaydin:claude/fix-redpanda-config-race

Conversation

@alpcanaydin

@alpcanaydin alpcanaydin commented Oct 8, 2026 •

Copy link
Copy Markdown

Summary

RedpandaContainer can start Redpanda before its redpanda.yaml is in place.

containerStarted copies two files, one after the other: the starter script, then redpanda.yaml with the mapped Kafka port. The container command runs the starter script as soon as the script exists, so it races the second copy. On a busy Docker host (a CI runner running other containers, for example) Redpanda reads the image's default config:

redpanda.advertised_kafka_api:[{:{host: 127.0.0.1, port: 9092}}]

The wait strategy still passes, because Successfully started Redpanda! is logged either way. Two failures follow:

  • Clients bootstrap through the mapped port and are then told to use 127.0.0.1:9092, so produce, consume and admin requests time out (KafkaJSCreateTopicError: Local: Timed out, ERR__TIMED_OUT).
  • If redpanda.yaml lands while Redpanda is starting, Redpanda exits and the start fails with Log stream ended and message "Successfully started Redpanda!" was not received.

We hit both intermittently in our own CI on GitHub-hosted runners.

Change

The container command now waits until redpanda.yaml holds the # Injected by testcontainers marker that the template already writes on its first line, then execs rpk redpanda start with the same arguments as before. The starter script and its second copy are gone.

containerStarted copies the config to redpanda.yaml.testcontainers and moves it into place with one mv. Docker writes a copied file in place: it creates the file empty and then writes the body, so a split write could expose the marker line before the rest of the config. A rename on the same filesystem makes redpanda.yaml all-or-nothing, so the starter sees either the image default or the whole file.

The marker wait is the approach of the Java and Go modules. Their entrypoint-tc.sh waits for the same marker before it starts Redpanda:

The rename goes one step further than those modules, after review feedback on this PR.

Verification

Regression test should connect when the config reaches the container late and in parts writes each copied file in two parts, first line then whole file, with a 1 s pause between them, as a busy Docker host can. It then asserts a message round trip.

Red, against the original implementation (starter script):

npx vitest run packages/modules/redpanda/src/redpanda-container.test.ts -t "in parts"
× should connect when the config reaches the container late and in parts 3458ms
  Error: Log stream ended and message "Successfully started Redpanda!" was not received

Red, against the marker wait without the rename (the first commit of this PR):

× should connect when the config reaches the container late and in parts 32669ms
  KafkaJSConnectionError: broker transport failure
redpanda.advertised_kafka_api:[]

Redpanda started on the first line alone, so it advertised no Kafka address.

An earlier version of the test only delayed each copy by 1 s. Against the original implementation it timed out after 240 s, and Redpanda advertised the image default:

redpanda.advertised_kafka_api:[{:{host: 127.0.0.1, port: 9092}}]

Green, with the marker wait and the rename:

npx vitest run packages/modules/redpanda/src/redpanda-container.test.ts
Test Files  1 passed (1)
     Tests  5 passed (5)
redpanda.advertised_kafka_api:[{external:{host: localhost, port: 33310}}, {internal:{host: 127.0.0.1, port: 9093}}]

Also run:

  • npx biome ci --error-on-warnings package.json packages/modules/redpanda: no findings.
  • npx tsc -b packages/testcontainers packages/modules/redpanda: passes.

Run on macOS with OrbStack (Docker 29.4.0), Node 24.15.0, image redpandadata/redpanda:v26.2.3.

The first commit of this PR, applied as a pnpm patch to @testcontainers/redpanda@12.2.0, keeps our CI's previously failing integration suite green. Before the patch, a probe that held the second copy back failed every start once the gap reached 150 ms (15 of 15 starts across 150, 200, 300 and 400 ms). Gaps of 50 and 100 ms passed on this machine. With the patch, the same probe, delaying each copy by 150, 400 or 1000 ms, passed 9 of 9 starts.

Note: vitest.config.ts retries tests 3 times on CI, which can hide this race in this repository's own runs.

Semver impact

patch. The public API is unchanged: same class, same methods, same Redpanda arguments. Only the internal start mechanism changes. The removed /testcontainers_start.sh file and the Waiting for script... log line were never part of the API.

Suggested labels: bug, patch.

@netlify

netlify Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for testcontainers-node ready!

Name Link
🔨 Latest commit 7fdc665
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-node/deploys/6ac745222436870007821550
😎 Deploy Preview https://deploy-preview-1483--testcontainers-node.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai

coderabbitai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3a0cd619-1b55-4f71-bda2-5e6d802185b1
📥 Commits

Reviewing files that changed from the base of the PR and between bf08e38 and 7fdc665.

📒 Files selected for processing (2)
  • packages/modules/redpanda/src/redpanda-container.test.ts
  • packages/modules/redpanda/src/redpanda-container.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

RedpandaContainer now waits for an injected configuration marker before starting Redpanda. It writes the rendered configuration to a staging path and renames it into place. A failed rename produces an error with the exit code and command output. A new test delays content-copy calls and checks message production and consumption.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 7fdc6

The delayed-configuration regression is covered, and the normal startup path publishes the configuration before readiness checks. No concrete merge-blocking issue was established.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the primary change: delaying Redpanda startup until its configuration is in place.
Description check ✅ Passed The description directly explains the Redpanda configuration race, the marker-based startup wait, atomic rename, regression test, and verification results.
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 85538a5a-76dd-4724-a74b-7028e953fd57
📥 Commits

Reviewing files that changed from the base of the PR and between f73de97 and bf08e38.

📒 Files selected for processing (2)
  • packages/modules/redpanda/src/redpanda-container.test.ts
  • packages/modules/redpanda/src/redpanda-container.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Comment thread packages/modules/redpanda/src/redpanda-container.ts

This branch has not been deployed

No deployments
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.

1 participant