Skip to content

test(core): drop vacuous URLError wait-strategy case - #1116

Open
cpruijsen wants to merge 3 commits into
testcontainers:mainfrom
cpruijsen:fix/issue-1115
Open

test(core): drop vacuous URLError wait-strategy case#1116
cpruijsen wants to merge 3 commits into
testcontainers:mainfrom
cpruijsen:fix/issue-1115

Conversation

@cpruijsen

Copy link
Copy Markdown

HttpWaitStrategy leaks a file descriptor per failed request. A wait strategy polls, so a container
that takes a while to become healthy leaks one descriptor per attempt, and a suite waiting on several
containers can exhaust the limit.

urlopen is used in a with, so the success path closes. HTTPError is the leak: it is both an
exception and a response file object, so raising it hands back an open descriptor that the except
clause discards without closing.

src/testcontainers/core/wait_strategies.py now splits the handler. HTTPError is handled inside
with e:, which closes the wrapped response on the way out, and URLError, which carries no file
object, keeps the plain path.

Behaviour is otherwise unchanged: both still go to _handle_http_error and the strategy retries as
before.

The test asserts no descriptors are left open across repeated failing probes.

Fixes #1115

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

Bug: file descriptor leak in HttpWaitStrategy

1 participant