-
Notifications
You must be signed in to change notification settings - Fork 14.3k
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 bug that makes AirflowSecurityManagerV2
leave transactions in the idle in transaction
state
#39935
Fix bug that makes AirflowSecurityManagerV2
leave transactions in the idle in transaction
state
#39935
Conversation
…he `idle in transaction` state. The problem is due to the combined usage of the `@cached_property` and `@provide_session` decorators on top of the `_auth_manager_is_authorized_map` method. `@cached_property` makes the `create_session` context manager get consumed and not be available to the nested functions.
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)
|
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.
Thank you for providing so much details in the description! That helps a lot to understand the issue. (And thanks for fixing a bug I created :D)
Some tests are failing |
@vincbeck thanks for the heads up on the test failures. I'll take a look at those later today. Cheers. |
… just use the session object that we already have available through the Security Manager's `appbuilder` attribute.
let's add this fix to 2.9.2 |
added |
Is it possiblw to add test to avoid regression? |
…ssions and instead uses the session already available through the `appbuilder` object that is attached to it.
@eladkal great idea. In c2f6a15 I added a test that makes sure the Security Manager doesn't create extra DB sessions and instead uses the session already available through the The test fails for the previous version of the Security Manager. Cheers. |
Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions. |
…he `idle in transaction` state (apache#39935)
…he `idle in transaction` state (apache#39935)
…he `idle in transaction` state (apache#39935)
Description
This PR fixes a bug that makes
AirflowSecurityManagerV2
leave some transactions in theidle in transaction
state.The problem is due to the combined usage of the
@cached_property
and@provide_session
decorators on top of the_auth_manager_is_authorized_map
method: the@cached_property
decorator makes thecreate_session
context manager get consumed and not be available to wrap the nested functions.The fix presented here just makes sure each of the resource-retrieving nested functions in
_auth_manager_is_authorized_map
can use a session object with a clean state.Impact
This problem affects views that perform fine-grained access checks using resource ID (for example, editing variables, editing connections, etc).
Apart from the negative impact of having orphaned transactions in the
idle in transaction
state, this problem also may lead tosqlalchemy.exc.PendingRollbackError
exceptions whilst trying to edit a resource.The sqlalchemy pool (using the default settings) seems to just chug along reusing the connections that have orphaned transactions, until they get invalidated. Then, if the
Session
object that is automatically passed to the security manager's nested functions gets to use one of those invalidated connections, an exception like the following is thrown:Tweaking the sqlalchemy pool settings and using pgbouncer also seem to play a role in mitigating this issue. In any case, there are already some users reporting errors editing resources. See #39581.
I'm not familiar with the connection invalidation mechanisms within sqlalchemy pools, but that's definitely a component in generating errors like the above.
I stumbled upon this problem in a Postgres-based environment after upgrading to Airflow 2.9.1 (Python 3.11). I don't know if other DB backends are equally affected.
Reproducing
idle in transaction
transactions:idle in transaction
monitor command show orphaned transactions that won't go away...until the webserver is restartedThe problem goes away by applying the code in this PR.
^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named
{pr_number}.significant.rst
or{issue_number}.significant.rst
, in newsfragments.