Skip to content

Run the garbage collector between tests - #417

Open
DABH wants to merge 2 commits into
mainfrom
gc-between-tests
Open

DABH wants to merge 2 commits into
mainfrom
gc-between-tests

Conversation

@DABH

@DABH DABH commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Tests sometimes stall (fail) on CPython < 3.12 if we don't garbage collect between tests. This is pretty low level and required a lot of prodding but I was able to reproduce the bad/good behavior without/with this fix consistently.

Specifically, objects a test leaves in reference cycles are collected whenever an allocation crosses the collector's threshold, which can be on a workflow thread in the middle of a sandboxed import. redis-py's ConnectionPool.__del__ runs an import, and on CPython before 3.12 an import started by a finalizer while the same thread is inside importlib's module-lock acquire leaks that lock (python/cpython#91351). The next sandbox import of that module waits forever, which is the stall I was seeing in various tests today. Every stalled log I encountered shows the importlib KeyError during the ADK agent-patterns test, whereas no passing log does.

@DABH
DABH marked this pull request as ready for review November 13, 2026 05:52
@DABH
DABH requested review from a team as code owners November 13, 2026 05:52
Objects a test leaves in reference cycles were collected whenever an
allocation crossed the collector's threshold, which could be on a
workflow thread in the middle of a sandboxed import. redis-py's
ConnectionPool.__del__ runs an import, and on CPython before 3.12 an
import started by a finalizer while the same thread is inside
importlib's module-lock acquire leaks that lock (python/cpython#91351),
so the next sandbox import of that module waits forever. That is the
Python 3.10 CI stall. An autouse fixture now collects on the main
thread after every test.
@DABH
DABH enabled auto-merge (squash) November 13, 2026 19:27
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.

1 participant