Pebble32 opened a new pull request, #77898:
URL: https://github.com/apache/airflow/pull/77898

   related: #73311
   
   A cluster policy, listener or custom priority weight strategy that calls a 
`@provide_session` function without a session can crash the scheduler. The 
nested `create_session()` gets the scheduler's own scoped session, and its 
commit trips the `prohibit_commit` guard. The rollback and close after that 
expire and detach every object the scheduler holds.
   
   The scheduler then dies with `DetachedInstanceError`, often far from the 
cause. In #73311 that is `expand_mapped_task`, followed by a second one from 
`run.run_id` in the error handler. `Variable.get` swallows the guard error, so 
the log only shows "Unable to retrieve variable".
   
   #76547 fixed this for Variable and Connection lookups. This fixes it for 
every other caller.
   
   The guard now marks the session, and a scoped `create_session()` inside it 
yields that session without committing, rolling back or closing. The guard's 
owner keeps the transaction, so writes join it and are committed by 
`guard.commit()`. Outside the guard nothing changes.
   
   A separate session would have been the other option. But a nested write 
could then wait on row locks the scheduler holds, which would hang the loop.
   
   I tested it with a real scheduler and a mapped task over an upstream XCom, 
with a `task_instance_mutation_hook` that calls `DagModel.get_dagmodel`. On 
main the scheduler exits during expansion. With this change the mapped task 
instances are queued.
   


-- 
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]

Reply via email to