Repository navigation
Apply one startup deadline from container start to ready #1582
Copy link
Copy link
Open
Labels
enhancementNew feature or requestNew feature or requestmajorAn incompatible API changeAn incompatible API change
Description
What happens
withStartupTimeout(ms) reads as "the container must be ready within this long". It is applied per phase instead, so start() can take several times longer than the value given before it fails:
- The image pull has no limit.
- The port-binding wait has its own fixed 30 second limit, separate from the startup timeout.
- The wait strategy gets the full timeout, counted from the moment the wait begins.
- Modules that wait again in
containerStartedrestart the clock. Kafka and Redpanda applystartupTimeoutMsto a second wait, so a Kafka container with its default of 180 seconds can run for close to 360 before failing.
Expected
One deadline, fixed when the container is started. The port-binding wait, the wait strategy and the hooks each get what is left of it. When it runs out, the error says which phase was waiting and what the total budget was.
Where
startContainerandreuseContainerinpackages/testcontainers/src/generic-container/generic-container.tspackages/testcontainers/src/generic-container/inspect-container-util-ports-exposed.tspackages/testcontainers/src/wait-strategies/wait-strategy.tsand every strategycontainerStartedin the kafka, redpanda and couchbase modules
Notes
- This cannot be done compatibly. The strategy has to be told the deadline. Passing the remaining time through
withStartupTimeoutchanges the error text, which core tests assert exactly (not accessible after 3000ms), and changes the caller's strategy instance. A new argument towaitUntilReadyis an interface change. Hencemajor. - Go gets this from
context: each strategy callscontext.WithTimeout(ctx, timeout), so the caller's context is the ceiling and a strategy's own timeout can only shorten it. - Increase timeout for waiting for host port bindings to 30 seconds #1494 kept the port-binding limit independent of
withStartupTimeout, because tying them together would let each phase use the full timeout. A shared deadline removes that objection. - Decide whether the image pull counts towards the deadline.
- A compatible first step is being prepared separately: the remaining startup time is passed to
containerStarted, so module waits after the wait strategy stop restarting the clock. - Related: withStartupTimeout() is not applied to the port-binding pre-wait (hardcoded 10 s) — measured under CPU contention #1446, Fail the start when the container exits before its ports are bound #1513.
Dependencies
- Blocked by Pass the started container to
WaitStrategy.waitUntilReady#1558, SupportAbortSignalinstart(),execand other long-running calls #1560: both change whatwaitUntilReadyreceives. The deadline should travel in what they add, so the interface changes once. - Coordinate with Stop the container startup timeout overriding a wait strategy's own timeout #1523: the precedence between a container timeout and a strategy timeout has to be one rule.
- Coordinate with Add lifecycle hooks that do not need a subclass #1554: hooks should be given the remaining time through their context.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestmajorAn incompatible API changeAn incompatible API change
Activity