Repository navigation
Conversation
hkc-8010
marked this pull request as ready for review
November 5, 2026 04:41
1 task done
seanghaeli
suggested changes
Nov 12, 2026
A trigger's log was only uploaded when the runner reported it finished, so triggers still running when the triggerer stopped lost everything they had logged there. After kill(), shut the runner's sockets for reading, drain them, and upload and close every trigger log still open through the parallel watcher-log upload pool. Shutting the sockets for reading first keeps the drain from running forever when a trigger left a child process that keeps writing to the runner's stdout. Co-Authored-By: Claude <[email protected]>
hkc-8010
force-pushed
the
fix/triggerer-upload-logs-on-shutdown
branch
from
November 28, 2026 05:10
e6059af to
805197b
Compare
Contributor
Author
|
@seanghaeli I rebased onto main after #76527 and addressed both of your comments, replies are in the threads. Could you take another look when you get a chance? |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When the triggerer stops (a deploy, a pod replacement, any SIGTERM), every trigger that is still running loses what it logged on that triggerer. A trigger's log is uploaded to remote storage only when the runner reports the trigger finished, and a trigger that is running at shutdown never reports that. Its file stays on the local disk of a pod that is going away. The trigger then resumes on another triggerer, which writes its own
.trigger.<job_id>.log, so the task log in the UI jumps from "Pausing task as DEFERRED" straight to the new triggerer's "trigger ... starting", with nothing in between.We hit this on a production deployment where an image deploy restarted the triggerer while 32 triggers were running, and a data-wait trigger lost three hours of log.
Airflow 2 did not have this gap.
TriggererHandlerWrapper.close()closed every open per-trigger handler at shutdown, and the object-store task handlers upload on close (see #37206). That path went away when the triggerer moved toTriggerRunnerSupervisor.Change
After
kill()inTriggererJobRunner._execute, the supervisor now:stop_taking_output()), then drains them with the existingcleanup_sockets_after_kill().kill()can return with log lines still unread, for example the "trigger completed" lines the runner writes as it cancels its triggers. Shutting the read side first makes the drain stop at what is already queued, so a trigger's child process that inherited the runner's stdout and keeps writing cannot keep it running forever (Socket drain after a kill never ends while a child process keeps writing #76867).logger_cache.close_trigger_log_files()(added in Give each asset watcher its own log file on the triggerer #76527) did this for watcher files only; it now covers task trigger logs too, through the same 16-threadupload_and_close_all(). A failed upload does not stop the others and every file is closed.This also covers the second item of #76867: the watcher files are now uploaded after the drain, so the runner's last lines reach them.
Testing
test_execute_closes_trigger_files_after_the_runner_exits:_executecallskill,stop_taking_output,cleanup_sockets_after_kill, thenclose_trigger_log_files, in that order.test_close_trigger_log_files_uploads_every_trigger_log: watcher and task trigger logs are both uploaded and closed, and a failing upload does not stop the others.test_trigger_log_uploaded_when_triggerer_stops_before_trigger_finishes: starts the real runner subprocess with a 1 hourTimeDeltaTrigger, shuts it down, and checks the uploaded file has both the "starting" line and the "trigger completed" line written during shutdown. Skipped on macOS, whereshutdown(SHUT_RD)discards queued data.test_drain_after_kill_ends_while_a_trigger_child_keeps_writing: a real child process floods the socket; the drain returns and still delivers the line queued before the kill.shutdown(), watcher-only upload, no drain call) and each fails its test on the assertion that names the bug.test_triggerer_job.pypasses in full (346 passed), and the tests above pass on Linux / Python 3.11 in the CI image.No new deadline was added. With 16 upload threads, the 1000 triggers at 50 ms each case from review (51s serially) works out to about 3s. That is arithmetic, I did not re-measure it.
No newsfragment, since this is a bugfix.
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code following the guidelines
🤖 Generated with Claude Code