-
Notifications
You must be signed in to change notification settings - Fork 15.3k
Fix: Unclosed aiohttp ClientSession and TCPConnector in DatabricksRunNowOperator (deferrable=True) #52119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: Unclosed aiohttp ClientSession and TCPConnector in DatabricksRunNowOperator (deferrable=True) #52119
Conversation
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide (https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
|
Awesome, @SalikramPaudel. Thank you for the fix. Cannot wait for upgrading to this version :-) |
cc: @pankajkoti => since you are working on this operator's Airflow 3 compatibility, maybe you can take a look as well ? |
6fba668
to
ea2ead1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for your great first contribution @SalikramPaudel 👏🏽
…redentials When using `DatabricksRunNowOperator` with `deferrable=True` and Azure authentication, unclosed aiohttp sessions were reported for both `ClientSecretCredential` and `ManagedIdentityCredential`. This fix ensures that: - `ClientSecretCredential` is used within an `async with` block to auto-close the session safely. - `ManagedIdentityCredential` is also used with `async with` (supported in azure-identity >= 1.7.0b2). This prevents runtime warnings like: - "Unclosed client session" - "Unclosed connector" The fix improves resource handling and aligns with Azure SDK best practices.
…manager flow Production now wraps `azure.identity.aio.ClientSecretCredential` in `async with`, so patching only `__init__`/`get_token` left the real `__aenter__` to explode with “AttributeError: _client”. The tests are refactored to: * Patch the credential class itself instead of individual methods. * Return a fully mocked object that implements `__aenter__`, `__aexit__`, and `get_token`, preserving existing assertions on constructor kwargs and token scope. * Apply the same change to both `TestDatabricksHookAsyncAadTokenOtherClouds` and `TestDatabricksHookAsyncAadTokenSpOutside`. No production code is affected; the update silences the failing async test suites introduced by the resource-cleanup PR.
ea2ead1
to
1d1b4e4
Compare
Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions. |
Closes: #51910
What this PR does
Fixes unclosed
aiohttp.ClientSession
andTCPConnector
warnings when usingDatabricksRunNowOperator
withdeferrable=True
in Airflow 3.0.2 and Databricks Provider 7.4.0.Background
As described in #51910, the following errors appear during deferrable task execution:
These indicate improper async resource cleanup during trigger polling.
Fix
aiohttp.ClientSession
andTCPConnector
are properly closedStatus
Opening as a Draft PR to allow early feedback.