test(core): drop vacuous URLError wait-strategy case - #1116
Open
cpruijsen wants to merge 3 commits into
Open
Conversation
HTTPError wraps the temporary file holding the response body. When a container's HTTP endpoint answered with an error status while the HttpWaitStrategy was still polling, the exception was discarded without closing it, leaking a file descriptor (and a ResourceWarning under -Werror) on every failed attempt. Use the caught HTTPError as a context manager so the response file is released on every path. URLError carries no file object and keeps the existing handling. Closes testcontainers#1115
The split except clause for HTTPError/URLError in _try_http_request was missing coverage for a bare URLError.
The assertion returned False both with and without the HTTPError close fix, so it did not lock in the leak change.
cpruijsen
force-pushed
the
fix/issue-1115
branch
from
September 14, 2026 14:34
5dea8c8 to
f703e06
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
HttpWaitStrategyleaks a file descriptor per failed request. A wait strategy polls, so a containerthat takes a while to become healthy leaks one descriptor per attempt, and a suite waiting on several
containers can exhaust the limit.
urlopenis used in awith, so the success path closes.HTTPErroris the leak: it is both anexception and a response file object, so raising it hands back an open descriptor that the
exceptclause discards without closing.
src/testcontainers/core/wait_strategies.pynow splits the handler.HTTPErroris handled insidewith e:, which closes the wrapped response on the way out, andURLError, which carries no fileobject, keeps the plain path.
Behaviour is otherwise unchanged: both still go to
_handle_http_errorand the strategy retries asbefore.
The test asserts no descriptors are left open across repeated failing probes.
Fixes #1115