-
-
Notifications
You must be signed in to change notification settings - Fork 257
Description
Problem
When calling .withStartupTimeout(ms) on a container, the timeout is not applied to the internal port binding check. This causes the error:
Error: Timed out after 10000ms while waiting for container ports to be bound to the host
Root Cause
In generic-container.ts, the function inspectContainerUntilPortsExposed() is called without passing the startupTimeoutMs value:
// Current code (line ~206-207)
const inspectResult = await inspectContainerUntilPortsExposed(
() => client.container.inspect(container),
container.id
// startupTimeoutMs is NOT passed here!
);The inspectContainerUntilPortsExposed function has a hardcoded default timeout of 10 seconds:
// inspect-container-util-ports-exposed.ts
export async function inspectContainerUntilPortsExposed(
inspectFn: () => Promise<ContainerInspectInfo>,
containerId: string,
timeout = 10_000 // ← hardcoded default
): Promise<ContainerInspectInfo>Impact
This affects containers that require more than 10 seconds to bind ports, such as:
- Kafka in KRaft mode (especially versions 7.x and older)
- Other slow-starting containers with complex initialization
Proposed Fix
Pass this.startupTimeoutMs to inspectContainerUntilPortsExposed() in both startContainer() and reuseContainer() methods:
const inspectResult = await inspectContainerUntilPortsExposed(
() => client.container.inspect(container),
container.id,
this.startupTimeoutMs // ← pass the configured timeout
);Reproduction
const container = new KafkaContainer('confluentinc/cp-kafka:7.5.0')
.withStartupTimeout(60_000) // Set to 60 seconds
.withKraft()
.start(); // Still fails after 10 seconds with port binding errorEnvironment
testcontainers version: 11.12.0
Node.js version: v24.10.0
Docker version: Docker version 29.2.1, build a5c7197