airflow icon indicating copy to clipboard operation
airflow copied to clipboard

Triggerer stops heartbeating while it uploads the logs of many finished triggers

Open seanghaeli opened this issue 1 week ago • 1 comments

When many deferred tasks finish at once with remote logging on, the triggerer uploads each finished trigger's log inline in its main loop, one after the other (TriggerRunnerSupervisor._handle_request, TriggerStateChanges: upload_to_remote() then close() per finished trigger). While that runs it doesn't heartbeat or handle events. After a long batch it logs that its runner looks deadlocked and skips its heartbeat, and with more than one triggerer its other triggers are reassigned and run twice.

This happens on ordinary workloads: many deferrable sensors waiting on one external event, or a restart after which many timers are already due.

Suggestion: upload finished triggers' logs from a small thread pool instead of inline, so the main loop keeps heartbeating. The pool size also bounds how hard the remote store is hit.

Done when: with remote logging on, a few thousand triggers finishing together don't stop the triggerer's heartbeat, their logs are all uploaded, and no trigger is reassigned, with a test.

seanghaeli avatar Nov 19 '26 03:11 seanghaeli

Hi, I reproduced this locally against main (fa1aa9de).

With each log upload taking 0.1s, a single TriggerStateChanges message with 400 finished triggers holds _handle_request for about 40s, because finalize_trigger_log uploads each log inline, one after another. That is past the 30s runner_health_check_threshold, so heartbeat() would treat the runner as deadlocked, skip the heartbeat, and the scheduler would reassign the triggers.

My approach would be to move the finished-trigger log uploads in finalize_trigger_log off the supervisor main loop into a small bounded thread pool, so _handle_request returns promptly and the main loop keeps heartbeating. Uploads would still complete before the log file is closed.

Could I work on this? Happy to be assigned if that works.

Update: I have a working version of this on my fork, commit 88cc97d8f07b191a6d5543c55874c9f59cd5c833 on branch fix-triggerer-log-upload-pool-77278. finalize_trigger_log now submits the upload and close to a four worker thread pool, and creation of a trigger whose log path still has an upload in flight is deferred to the next pass so the new logger cannot truncate the file mid upload. With the fix, the same 400 trigger repro returns in about 0s, and the triggerer job tests pass (213 passed). Happy to open a PR from it once assigned.

PCTEJA avatar Nov 19 '26 05:11 PCTEJA