ghostbody opened a new issue #22271:
URL: https://github.com/apache/airflow/issues/22271


   ### Apache Airflow version
   
   2.2.1
   
   ### What happened
   
   
   Airflow reports `Mysql Error: Locked Wait Timeout`. And we take a look at 
the code which requires db lock and find this.
   
   
   
![image](https://user-images.githubusercontent.com/8371330/158322403-aa085f2a-51ec-4c5a-94ca-43c85594691f.png)
   
   
   
![image](https://user-images.githubusercontent.com/8371330/158323958-0ee26939-0192-47a5-b43e-9b09e9834fe2.png)
   
   
   ### What you think should happen instead
   
   
   should we take this?
   
   ```python
           if lock_for_update:
               ti: Optional[TaskInstance] = with_row_locks(qry, of=cls).first()
   ```
   
   Use `with_row_locks` in  `utils` and make sure that the `of ` argument is 
included is better~ 
   
   ### How to reproduce
   
   
   session A:
   
   ```python
   
   from airflow.models.taskinstance import TaskInstance
   
   from airflow.utils.session import create_session
   
   session = create_session().__enter__()
   
   ti = session.query(TaskInstance).first()
   
   print(ti.dag_id)  # get this dag_id as dag_id_x
   
   ti.refresh_from_db(session=session, lock_for_update=True)
   
   # And then hold this lock
   
   ```
   
   session B
   
   ```python
   
   from airflow.models.dagrun import DagRun
   
   from airflow.utils.session import create_session
   
   session = create_session().__enter__()
   
   dag_run = 
session.query(DagRun).filter_by(dag_id='dag_id_x').with_for_update().first()
   
   # this will hangs...
   
   ```
   
   
   ### Operating System
   
   ubuntu 20.04
   
   ### Versions of Apache Airflow Providers
   
   _No response_
   
   ### Deployment
   
   Other Docker-based deployment
   
   ### Deployment details
   
   _No response_
   
   ### Anything else
   
   _No response_
   
   ### Are you willing to submit PR?
   
   - [X] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [X] I agree to follow this project's [Code of 
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
   


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