You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "ephraimbuddy (via GitHub)" <gi...@apache.org> on 2023/02/22 10:49:40 UTC

[GitHub] [airflow] ephraimbuddy commented on issue #25297: on_failure_callback is not called when task is terminated externally

ephraimbuddy commented on issue #25297:
URL: https://github.com/apache/airflow/issues/25297#issuecomment-1439807739

   We can solve this by running the callback in the signal handler:
   ```diff
   diff --git a/airflow/models/taskinstance.py b/airflow/models/taskinstance.py
   index c74ff8b6b0..0c361d0d41 100644
   --- a/airflow/models/taskinstance.py
   +++ b/airflow/models/taskinstance.py
   @@ -1528,7 +1528,8 @@ class TaskInstance(Base, LoggingMixin):
                    return
                self.log.error("Received SIGTERM. Terminating subprocesses.")
                self.task.on_kill()
   -            raise AirflowException("Task received SIGTERM signal")
   +            if self.task.on_failure_callback:
   +                self._run_finished_callback(self.task.on_failure_callback, context, "on_failure")
    
            signal.signal(signal.SIGTERM, signal_handler)
   ```
   The raised exception is somehow lost and I think the loss is similar to the explanations in this blog: https://anonbadger.wordpress.com/2018/12/15/python-signal-handlers-and-exceptions/


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org