andreahlert commented on code in PR #61627:
URL: https://github.com/apache/airflow/pull/61627#discussion_r2794373113


##########
task-sdk/src/airflow/sdk/execution_time/supervisor.py:
##########
@@ -2078,7 +2078,33 @@ def supervise(
             sentry_integration=sentry_integration,
         )
 
-        exit_code = process.wait()
+        # Forward termination signals to the task subprocess so that the 
operator's
+        # on_kill() hook is invoked on graceful shutdown (e.g. K8s pod 
SIGTERM).
+        # Without this, the supervisor exits on SIGTERM without notifying the 
child,
+        # leaving spawned resources (pods, subprocesses, etc.) running.
+        prev_sigterm = signal.getsignal(signal.SIGTERM)
+        prev_sigint = signal.getsignal(signal.SIGINT)
+
+        def _forward_signal(signum, frame):
+            log.info(
+                "Received signal, forwarding to task subprocess",
+                signal=signal.Signals(signum).name,
+                pid=process.pid,
+            )
+            try:
+                os.kill(process.pid, signum)
+            except ProcessLookupError:
+                pass

Review Comment:
   LGTM. I'll add the comment and also throw in a log.debug there, same pattern 
as the psutil.NoSuchProcess handling in kill() a few lines above. to keeps the 
shutdown flow observable. 



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