Skip to content

fix: apply withStartupTimeout() to the port-binding pre-wait - #1447

Open
kenzox wants to merge 1 commit into
testcontainers:mainfrom
kenzox:fix/port-bind-wait-respects-startup-timeout
Open

fix: apply withStartupTimeout() to the port-binding pre-wait#1447
kenzox wants to merge 1 commit into
testcontainers:mainfrom
kenzox:fix/port-bind-wait-respects-startup-timeout

Conversation

@kenzox

@kenzox kenzox commented Aug 27, 2026

Copy link
Copy Markdown

Fixes #1446.

GenericContainer.start() waits for host port bindings (inspectContainerUntilPortsExposed) before the wait strategy runs, but neither call site passes this.startupTimeoutMs, so that pre-wait is always capped at the util's 10 s default and withStartupTimeout() does not apply to it.

This passes this.startupTimeoutMs at both call sites (reuseContainer and startContainer). When no startup timeout was configured the argument is undefined and the existing 10 s default still applies, so behaviour only changes for callers who explicitly asked for a longer budget.

Measured (12.1.0, six postgres:18-alpine containers starting concurrently on a 2-vCPU GitHub runner): port binding took up to 16.7 s and failed at 10 s despite withStartupTimeout(120_000); with this change the same suite passes.

Verified locally on the branch: npm ci → 0, tsc -p packages/testcontainers/tsconfig.json --noEmit → 0, eslint → 0, prettier → 0. The Docker-backed integration suite was not run here.

`GenericContainer.start()` waits for host port bindings via
`inspectContainerUntilPortsExposed` before the wait strategy runs, but
neither call site passed `this.startupTimeoutMs`, so that pre-wait was
always capped at the util's 10 s default and `withStartupTimeout()` did
not apply to it. Pass the configured value at both call sites; when no
startup timeout was configured the argument is `undefined` and the 10 s
default still applies.

Fixes testcontainers#1446

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@netlify

netlify Bot commented Aug 27, 2026

Copy link
Copy Markdown

Deploy Preview for testcontainers-node ready!

Name Link
🔨 Latest commit b917d69
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-node/deploys/6a90062724f1460008f79c5e
😎 Deploy Preview https://deploy-preview-1447--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 Aug 27, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c4abde90-06f8-4444-bfce-4fcc444cff98

📥 Commits

Reviewing files that changed from the base of the PR and between 99ff0a2 and b917d69.

📒 Files selected for processing (1)
  • packages/testcontainers/src/generic-container/generic-container.ts

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


Summary by CodeRabbit

  • Bug Fixes
    • Container startup now consistently respects the configured startup timeout when waiting for ports to become available.
    • Improved timeout behavior for both new and reused containers.

Walkthrough

GenericContainer now passes startupTimeoutMs to port-exposure inspection for reused and newly started containers.

Changes

Container startup timeout

Layer / File(s) Summary
Apply startup timeout to port inspection
packages/testcontainers/src/generic-container/generic-container.ts
Both container startup paths pass this.startupTimeoutMs to inspectContainerUntilPortsExposed.

Estimated code review effort: 2 (Simple) | ~5 minutes

Merge Risk: ⚪ Minimal · up to b917d

The configured startup timeout now also covers port-binding waits while the existing default behavior remains unchanged; no actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: cristianrgreco

Poem

A rabbit checks the ports at dawn

Reused containers carry on
New containers wait in line
Startup clocks now keep their time
The binding path is calm and bright

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: applying withStartupTimeout() to the port-binding pre-wait.
Description check ✅ Passed The description directly explains the hardcoded timeout problem, the fix at both call sites, preserved default behavior, and verification results.
Linked Issues check ✅ Passed The changes satisfy issue [#1446] by passing this.startupTimeoutMs to inspectContainerUntilPortsExposed() in both reuseContainer and startContainer paths while preserving the 10-second default when no…
Out of Scope Changes check ✅ Passed The changes are limited to the timeout propagation required by issue [#1446]. No unrelated code changes are identified.
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 1…
Full details: Linked Issues check

Explanation

The changes satisfy issue [#1446] by passing this.startupTimeoutMs to inspectContainerUntilPortsExposed() in both reuseContainer and startContainer paths while preserving the 10-second default when no timeout is configured.

Full details: Docstring Coverage

Explanation

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 1 files.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

Some tools did not complete. Review the errors below.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed: one or more packages not found in the registry.


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.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b917d69b3c

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

() => client.container.inspect(container),
container.id
container.id,
this.startupTimeoutMs

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Add a regression test for the timeout path

This bug fix changes GenericContainer.start() behavior, but there is no test proving that a custom withStartupTimeout() lets the port-binding pre-wait run past the utility's 10s default; a future refactor could silently reintroduce the cap. Please add a focused regression test around this startup path that fails before the change and passes after it.

AGENTS.md reference: AGENTS.md:L29-L34

Useful? React with 👍 / 👎.

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.

withStartupTimeout() is not applied to the port-binding pre-wait (hardcoded 10 s) — measured under CPU contention

1 participant