test(google): disarm genai client finalizers in realtime tests - #6975
Open
rkfshakti wants to merge 1 commit into
Open
test(google): disarm genai client finalizers in realtime tests#6975rkfshakti wants to merge 1 commit into
rkfshakti wants to merge 1 commit into
Conversation
AsyncClient.__del__ and BaseApiClient.__del__ schedule aclose() on whatever event loop is running when the garbage collector reaches them. Sessions in this module close their clients explicitly in RealtimeSession.aclose(), so the finalizers are pure redundancy — but they leak pending tasks into whichever test happens to be running at GC time, and fail_on_leaked_tasks charges them to that test (issue livekit#6881). Disarm both finalizers at module import, in the only module that constructs genai clients. Verified: without the disarm, dropping a client schedules 2 pending AsyncClient.aclose tasks; with it, zero.
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.
Fixes #6881
Problem
tests/test_plugin_openai_stt_context.py::test_use_realtime_defaults_to_the_only_transport_a_model_has[gpt-realtime-whisper-True]intermittently fails with:That test is synchronous and never touches google. The tasks come from
tests/test_plugin_google_realtime.py— the only module in the unit suite that constructs genai clients.Root cause
AsyncClient.__del__andBaseApiClient.__del__both do this unconditionally, with no check for a client that was already closed:RealtimeSession.aclose()closesclient.aio, but that does not disarm the finalizer — the object stays garbage until the collector reaches it, which can be several modules later.fail_on_leaked_tasksdiffsasyncio.all_tasks()around each test, so the task is charged to whatever test happens to be running then.Fix
Disarm both finalizers at module import in
tests/test_plugin_google_realtime.py— the only module that constructs genai clients. Sessions already close their clients explicitly, so the finalizers are pure redundancy.Verified:
AsyncClient.aclosetasks on the running loop