bnspopi opened a new pull request, #77349: URL: https://github.com/apache/airflow/pull/77349
`cleanup_sockets_after_kill()` reads each log socket of a killed subprocess until the socket is empty or closed. If the subprocess had started a child that inherited its stdout and keeps writing, the socket never closes, and a writer that is faster than the log handling keeps it from ever being empty, so the drain never returns. #76867 describes how this hits the Dag processor: a Dag file's parse starts such a child, the parse times out, and the processor stops parsing for good with a stale heartbeat and a busy CPU core. This shuts down the read side of each log socket before draining it, as the issue proposes. The drain then reads what was already queued and sees EOF, and the leftover writer gets `EPIPE` on its next write. The `requests` socket is not drained today and is left as it is. This covers the first item of #76867 only. The second item, draining the trigger runner's sockets on stop before the watcher log files are uploaded, belongs with #76527 and is not part of this change. @schizophrenicmaniac said in the issue that they would work on this with the same approach. I did not find a PR for it; I am happy to close this one if theirs is on the way. Tests, run on Linux: - New `test_cleanup_sockets_after_kill_ends_while_a_child_keeps_writing` starts a real child process that floods the socket and checks that the drain returns and still delivers the line that was queued before it. Without the source change it fails after the 5 second join timeout; with it, it passes in under a second. - `task-sdk/tests/task_sdk/execution_time/test_supervisor.py`: 383 passed, 1 skipped. - `airflow-core/tests/unit/dag_processing/test_processor.py`: 153 passed. Not tested: the end-to-end Dag processor scenario from the issue (a real parse timeout with a surviving child), and macOS. related: #76867 --- ##### Was generative AI tooling used to co-author this PR? - [X] Yes (Claude Code) Generated-by: Claude Code following [the guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions) 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
