Skip to content

fix: guard aclose() against missing attributes during GC#2243

Open
sunhwan wants to merge 2 commits intogoogleapis:mainfrom
sunhwan:fix/aclose-attribute-error-on-gc
Open

fix: guard aclose() against missing attributes during GC#2243
sunhwan wants to merge 2 commits intogoogleapis:mainfrom
sunhwan:fix/aclose-attribute-error-on-gc

Conversation

@sunhwan
Copy link
Copy Markdown

@sunhwan sunhwan commented Apr 7, 2026

Summary

BaseApiClient.__del__ schedules aclose() as an async task during garbage collection (line 2118). By the time the task
executes, Python may have already partially destroyed the object, so attributes like _async_httpx_client,
_aiohttp_session, or _http_options may no longer exist. This causes unhandled AttributeError exceptions:

Task exception was never retrieved
future: <Task finished name='Task-2' coro=<BaseApiClient.aclose() done, ...>
  exception=AttributeError("'BaseApiClient' object has no attribute '_async_httpx_client'")>

Fix

Use getattr(self, ..., None) for all attribute accesses in aclose(), matching the defensive pattern already used by
close() (which guards with and self._httpx_client). This ensures aclose() is safe to call on a partially-destroyed
object.

@google-cla
Copy link
Copy Markdown

google-cla bot commented Apr 7, 2026

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.

@Venkaiahbabuneelam Venkaiahbabuneelam self-assigned this Apr 8, 2026
@Venkaiahbabuneelam Venkaiahbabuneelam added size:S Code changes < 10 lines and removed size:S Code changes < 10 lines labels Apr 8, 2026
@Venkaiahbabuneelam
Copy link
Copy Markdown

Hi @sunhwan, Thanks for reaching out us!

I noticed some checks have failed. Kindly resolve the conflicts.

Thanks

@sunhwan
Copy link
Copy Markdown
Author

sunhwan commented Apr 8, 2026

Thanks, a fix is submitted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants