Repository navigation
DAGs with external python task are not killed when marked as Failed. #74298
|
It seems that any dag using an external python task are not killed when they are marked as Failed in the UI. Does anyone know what is happening here? For example, this dag (... is just a placeholder in this example. The actual dag would need the necessary params defined): When I click the "Failed" button in the UI to mark the dag as failed, I get the following log: I am using Airflow 3.2.2. |
Replies: 2 comments 2 replies
|
This is a known bug in the 3.2 line, and it's fixed in Airflow 3.3.1. When you mark the task as failed, the next heartbeat from the task gets a 409 and the supervisor kills the task process. That's the "Server indicated the task shouldn't be running anymore" line in your log. In 3.2.2 the signal only goes to the task-runner process itself. Your It was reported in #65505 and fixed by #65738. The fix puts the task-runner in its own process group and sends the signal to the whole group with If you can't upgrade yet, one workaround is to have the long-running function notice that its parent is gone and exit on its own: import os
import sys
import time
parent = os.getppid()
while True:
if os.getppid() != parent:
sys.exit(1)
print("alive", flush=True)
time.sleep(1)That only helps for code that loops like this, but it stops the orphaned process from running forever. |
|
This is an interesting issue with external Python tasks. The logs clearly show that the task runner detects the failed state and attempts to terminate the process, but the external Python process continues running afterward. It would be useful to understand how the termination signal is propagated to the external environment and whether there is a recommended way to ensure the child process is cleaned up properly. |
This is a known bug in the 3.2 line, and it's fixed in Airflow 3.3.1.
When you mark the task as failed, the next heartbeat from the task gets a 409 and the supervisor kills the task process. That's the "Server indicated the task shouldn't be running anymore" line in your log. In 3.2.2 the signal only goes to the task-runner process itself. Your
@task.external_pythonfunction runs in a separate Python process that the task-runner starts withsubprocess.Popen, so it never receives the signal. Once the task-runner is killed, that child gets reparented and keeps running, which is why your log keeps printingaliveafter the termination message.It was reported in #65505 and fixed by #65738. Th…