Skip to content

Conversation

@hterik
Copy link
Contributor

@hterik hterik commented Feb 22, 2024

When a task is terminated, it get sent a SIGTERM signal, (through standard_task_runner.terminate).
This signal is picked up by taskinstance.py, where it injects an AirflowException into the current running task.

The exception raised there is now changed into a new AirflowTaskTerminated exception.
This new exception inherits BaseException, so that it is not caught and ignored accidentally by code that tries to perform ordinary error handling. Because termination requests should not be ignored.

This will improve reliability of cancelling tasks and will make error logs and error categorization more clear about the reason for failure.

(The terminate function does eventually send SIGKILL if the
SIGTERM is ignored, but waiting for that should not be necessary)

When a task is terminated, it get sent a SIGTERM signal,
(through standard_task_runner.terminate).
This signal is picked up by taskinstance.py, where it injects an
AirflowException into the current running task.

The exception raised there is now changed into a new
AirflowTaskTerminated exception.
This new exception inherits BaseException, so that it
is not caught and ignored accidentally by code that tries
to perform ordinary error handling. Because termination requests
should not be ignored.

This will improve reliability of cancelling tasks and will make
error logs and error categorization more clear about the reason
for failure.

(The terminate function does eventually send SIGKILL if the
 SIGTERM is ignored, but waiting for that should not be necessary)

See https://docs.python.org/3/library/exceptions.html#exception-hierarchy
@hterik hterik force-pushed the add_airflowtaskterminated_for_sigterm branch from 349cb34 to ff5f042 Compare February 22, 2024 11:26
Copy link
Member

@potiuk potiuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@potiuk potiuk merged commit 45eeff4 into apache:main Feb 22, 2024
sudiptob2 pushed a commit to Satoshi-Sh/airflow that referenced this pull request Feb 22, 2024
…37613)

When a task is terminated, it get sent a SIGTERM signal,
(through standard_task_runner.terminate).
This signal is picked up by taskinstance.py, where it injects an
AirflowException into the current running task.

The exception raised there is now changed into a new
AirflowTaskTerminated exception.
This new exception inherits BaseException, so that it
is not caught and ignored accidentally by code that tries
to perform ordinary error handling. Because termination requests
should not be ignored.

This will improve reliability of cancelling tasks and will make
error logs and error categorization more clear about the reason
for failure.

(The terminate function does eventually send SIGKILL if the
 SIGTERM is ignored, but waiting for that should not be necessary)

See https://docs.python.org/3/library/exceptions.html#exception-hierarchy
@ephraimbuddy ephraimbuddy added this to the Airflow 2.9.0 milestone Mar 6, 2024
@ephraimbuddy ephraimbuddy added the type:improvement Changelog: Improvements label Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:improvement Changelog: Improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants