You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by po...@apache.org on 2021/11/27 16:52:30 UTC
[airflow] branch main updated: Workaround occasional deadlocks with MSSQL (#19856)
This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new e87856d Workaround occasional deadlocks with MSSQL (#19856)
e87856d is described below
commit e87856df32275768ba72ed85b6ea11dbca4d2f48
Author: Jarek Potiuk <ja...@potiuk.com>
AuthorDate: Sat Nov 27 17:51:56 2021 +0100
Workaround occasional deadlocks with MSSQL (#19856)
We already have a mechanism to retry operations that could result
in temporary deadlocks - this have been helpful with handling MySQL
deadlocks - however similar problems occur occasionally in MSSQL and
there we get a DBAPIError rather than OperationalError:
`sqlalchemy.exc.DBAPIError: (pyodbc.Error) ('40001', '[40001]
[Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Transaction
(Process ID 55) was deadlocked on lock resources with another process
and has been chosen as the deadlock victim. Rerun the transaction.
(1205) (SQLExecDirectW)');
This PR adds DBAPIError to the list of errors that are handled
by `run_with_db_retries` to mitigate such occasional deadlocks.
---
airflow/utils/retries.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/airflow/utils/retries.py b/airflow/utils/retries.py
index 2bb76b1..c4124c8 100644
--- a/airflow/utils/retries.py
+++ b/airflow/utils/retries.py
@@ -21,7 +21,7 @@ from inspect import signature
from typing import Any, Optional
import tenacity
-from sqlalchemy.exc import OperationalError
+from sqlalchemy.exc import DBAPIError, OperationalError
from airflow.configuration import conf
@@ -32,7 +32,7 @@ def run_with_db_retries(max_retries: int = MAX_DB_RETRIES, logger: Optional[logg
"""Return Tenacity Retrying object with project specific default"""
# Default kwargs
retry_kwargs = dict(
- retry=tenacity.retry_if_exception_type(exception_types=OperationalError),
+ retry=tenacity.retry_if_exception_type(exception_types=(OperationalError, DBAPIError)),
wait=tenacity.wait_random_exponential(multiplier=0.5, max=5),
stop=tenacity.stop_after_attempt(max_retries),
reraise=True,