fix: guard against missing _async_httpx_client in aclose()#2297
Open
jrcks67 wants to merge 1 commit intogoogleapis:mainfrom
Open
fix: guard against missing _async_httpx_client in aclose()#2297jrcks67 wants to merge 1 commit intogoogleapis:mainfrom
jrcks67 wants to merge 1 commit intogoogleapis:mainfrom
Conversation
When __init__ raises before _async_httpx_client is assigned (e.g. an auth error thrown before any HTTP call), __del__ still schedules aclose() as an asyncio task. aclose() then crashes with: AttributeError: 'BaseApiClient' object has no attribute '_async_httpx_client' The error surfaces as an unhandled asyncio task exception, which is swallowed silently unless asyncio debug mode is on. close() already guards the equivalent sync path with `and self._httpx_client`; apply the same pattern to aclose() using getattr(..., None) to safely handle the uninitialized case. Fixes the unhandled task exception reported when using the async client with a missing or invalid API key.
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
Hi @jrcks67, Thanks for reaching out us! It looks like some checks failed. Kindly resolve the conflicts. Thanks |
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.
Problem
When
BaseApiClient.__init__raises before_async_httpx_clientis assigned (e.g. an auth error thrown before any HTTP call is made),__del__still schedulesaclose()as an asyncio task. That task then crashes with:The exception surfaces as an unhandled asyncio task exception — swallowed silently in production unless
PYTHONASYNCIODEBUG=1is set, making it hard to spot.Minimal repro (v1.66.0)
Traceback:
Fix
close()already guards the equivalent sync path withand self._httpx_client. Apply the same pattern toaclose()usinggetattr(..., None)to safely handle the case where_async_httpx_clientwas never set:One-line change, no behaviour difference in the normal path.