korex-f commented on code in PR #66633:
URL: https://github.com/apache/airflow/pull/66633#discussion_r3237146003


##########
task-sdk/src/airflow/sdk/execution_time/supervisor.py:
##########
@@ -2209,9 +2235,29 @@ def _configure_logging(log_path: str, client: Client) -> 
tuple[FilteringBoundLog
 
     with _remote_logging_conn(client):
         processors = logging_processors(json_output=json_logs)
+
     logger = structlog.wrap_logger(underlying_logger, processors=processors, 
logger_name="task").bind()
 
-    return logger, log_file_descriptor
+    try:
+        yield logger, log_file_descriptor
+    finally:
+        # Flush and close the remote handler now — AFTER the supervisor has
+        # drained all task log messages from the subprocess pipe (i.e. after
+        # process.wait() has returned).
+        #
+        # Without this, the only thing that ever closes the handler is
+        # Python's logging.shutdown() at process exit, which fires after
+        # supervise_task() returns. Any messages still queued in the handler
+        # at that point are silently dropped, producing:
+        #
+        # WatchtowerWarning: "Received message after logging system shutdown"

Review Comment:
   Thanks. I have made those comments provider-agnostic and use CloudWatch as 
an example rather than stating it as the only case.



-- 
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]

Reply via email to