dabla opened a new pull request, #77202: URL: https://github.com/apache/airflow/pull/77202
`KiotaRequestAdapterHook.get_async_conn` reads the adapter cache, then awaits the connection, then builds an adapter and writes it to the cache. Coroutines that use the same connection for the first time at once (several triggers starting together, or async tasks sharing an event loop) all read an empty cache while the first one is still awaiting the connection, so each builds its own request adapter. Only the last one stays in the cache. The other adapters still serve the request that built them, but `close()` can no longer reach them: it closes the adapter it pops from the cache. Their credential sessions are therefore never closed (`CachedAsyncTokenCredential.close()` is a no-op by design), and asyncio logs this at error level when they are garbage collected, in the middle of the task: ``` Unclosed client session client_session: <aiohttp.client.ClientSession object at 0x...> Unclosed connector ``` Each extra adapter also requests its own access token and opens its own connection to the API. In task logs this shows as N `Creating Microsoft Graph SDK client` blocks followed by N-1 `Unclosed client session` errors. The cache is now read again after the awaits. Nothing awaits between that lookup and the write, so one adapter is built per connection and every caller gets the cached one. The new test gathers five `get_async_conn` calls on an empty cache. Without the fix it fails with `Expected '_build_request_adapter' to have been called once. Called 5 times.` Checks run locally: `pytest providers/microsoft/azure/tests/unit/microsoft/azure/hooks/test_msgraph.py` (121 passed, 1 xfailed) and `prek run --files` on the two changed files. --- ##### Was generative AI tooling used to co-author this PR? - [X] Yes (please specify the tool below) Generated-by: Claude Code (Fable 5.2) following [the guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions) --- * Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information. Note: commit author/co-author name and email in commits become permanently public when merged. * For fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed. * When adding dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x). * For significant user-facing changes create newsfragment: `{pr_number}.significant.rst`, in [airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments). You can add this file in a follow-up commit after the PR is created so you know the PR number. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
