You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "dabla (via GitHub)" <gi...@apache.org> on 2025/04/18 15:22:43 UTC
[I] Deadlock in SchedulerJobRunner._executable_task_instances_to_queued on distributed Postgres databases using YugabyteDB [airflow]
dabla opened a new issue, #49437:
URL: https://github.com/apache/airflow/issues/49437
### Apache Airflow version
2.10.5
### If "Other Airflow 2 version" selected, which one?
_No response_
### What happened?
When running multiple Airflow schedulers in combination with a distributed Postgres-compatible database like YugabyteDB, the _set_state method of the TaskInstance can fail to update the task state correctly. This leads to synchronization issues in task state management, potentially causing scheduling anomalies or duplicated task runs.
This issue does not occur when:
A single scheduler is used with YugabyteDB, or
Multiple schedulers are used with a traditional single-node PostgreSQL instance.
The root cause is likely due to YugabyteDB's distributed nature and how it handles concurrent updates with conditionals (like WHERE state != <state>), which can behave subtly differently compared to standard PostgreSQL under race conditions.
Tested scenario's matrix
| Scenario | Database | Multiple Schedulers | Works? |
|----------------------------------------------|--------------|----------------------|--------|
| Standard PostgreSQL | ✅ Yes | ✅ Yes | ✅ |
| YugabyteDB (distributed Postgres-compatible) | ✅ Yes | ❌ No | ❌ |
| YugabyteDB (distributed Postgres-compatible) | ✅ Yes | ✅ No | ✅ |
### What you think should happen instead?
The provided _set_state refactor bellow ensures consistent and reliable updates to task states across all setups.
The improved method:
```
@staticmethod
@internal_api_call
def _set_state(
ti: TaskInstance | TaskInstancePydantic, state: TaskInstanceState, session: Session
) -> bool:
if isinstance(ti, TaskInstancePydantic):
ti.state = TaskInstanceState[ti.state]
logging.info("Setting task state for %s to %s", ti, state)
current_time = timezone.utcnow()
start_date = ti.start_date or current_time
if ti.state in State.finished or ti.state == TaskInstanceState.UP_FOR_RETRY:
end_date = ti.end_date or current_time
duration = (
(end_date - start_date).total_seconds() if start_date and end_date else None
)
else:
end_date = None
duration = None
result = session.execute(
update(TaskInstance)
.where(
TaskInstance.task_id == ti.task_id,
TaskInstance.dag_id == ti.dag_id,
TaskInstance.run_id == ti.run_id,
TaskInstance.map_index == ti.map_index,
TaskInstance.state != state,
)
.values(
state=state,
start_date=start_date,
end_date=end_date,
duration=duration,
)
)
return result.rowcount > 0
```
### How to reproduce
Use a distributed Postgres database using yugabyteDB in combination with multiple schedulers as one scheduler won't trigger the deadlock due to the fact that there isn't concurrency then.
### Operating System
RockyLinux 9.5
### Versions of Apache Airflow Providers
Latest stable versions
### Deployment
Other 3rd-party Helm chart
### 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: commits-unsubscribe@airflow.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Deadlock in SchedulerJobRunner._executable_task_instances_to_queued on distributed Postgres databases using YugabyteDB [airflow]
Posted by "dabla (via GitHub)" <gi...@apache.org>.
dabla commented on issue #49437:
URL: https://github.com/apache/airflow/issues/49437#issuecomment-2841418237
We will restest multiple schedulers with Airflow 3 in the future to see if the issue is still there.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Deadlock in SchedulerJobRunner._executable_task_instances_to_queued on distributed Postgres databases using YugabyteDB [airflow]
Posted by "dabla (via GitHub)" <gi...@apache.org>.
dabla commented on issue #49437:
URL: https://github.com/apache/airflow/issues/49437#issuecomment-2815699873
I've created a [PR](https://github.com/apache/airflow/pull/49439) for this.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Deadlock in SchedulerJobRunner._executable_task_instances_to_queued on distributed Postgres databases using YugabyteDB [airflow]
Posted by "raphaelauv (via GitHub)" <gi...@apache.org>.
raphaelauv commented on issue #49437:
URL: https://github.com/apache/airflow/issues/49437#issuecomment-3705282514
hi @dabla thanks for sharing this, did you end up running airlfow ( multiple schedulers ) with a yugabyteDB ?
Do you have some feedback to share ?
( BTW there is this presentation from airflow summit 2024 ->https://airflowsummit.org/sessions/2024/weathering-the-cloud-storms-with-multi-region-airflow-workflows/ )
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org