Repository navigation
Conversation
kaxil
force-pushed
the
handle-supervisor-signals
branch
4 times, most recently
from
December 9, 2024 09:00
257e1c6 to
691d183
Compare
kaxil
marked this pull request as ready for review
December 9, 2024 09:08
Member
Author
|
I will follow-up with a PR to handle signals for the actual Task process |
kaxil
commented
Dec 9, 2024
Member
Author
There was a problem hiding this comment.
I should probably also assert that a final TI patch was called, 🤔
Member
Author
There was a problem hiding this comment.
Can only do that if I call supervise instead of just proc._setup_signal_handlers()
Member
Author
There was a problem hiding this comment.
Alternative is:
def test_supervisor_signal_handling(self, mocker, monkeypatch, captured_logs):
"""Verify that the supervisor correctly handles signals and terminates the task process."""
mocker.patch("airflow.sdk.execution_time.supervisor.MIN_HEARTBEAT_INTERVAL", 0.01)
mock_client = MagicMock(spec=sdk_client.Client)
subprocess_pid = os.getpid()
def subprocess_main():
os.kill(subprocess_pid, signal.SIGTERM)
# It should not take 5 seconds. The process should terminate immediately
sleep(5)
proc = WatchedSubprocess.start(
path=os.devnull,
ti=TaskInstance(id=TI_ID, task_id="b", dag_id="c", run_id="d", try_number=1),
client=mock_client,
target=subprocess_main,
)
rc = proc.wait()
assert rc == -signal.SIGTERM
assert proc.final_state == TerminalTIState.FAILED
assert proc._exit_code == -signal.SIGTERM
assert {
'signal': signal.SIGTERM,
'process_pid': proc.pid,
'supervisor_pid': mocker.ANY,
'event': 'Received termination signal in supervisor. Terminating watched subprocess',
'timestamp': mocker.ANY,
'level': 'error',
'logger': 'supervisor'
} in captured_logs
assert {
'pid': proc.pid,
'exit_code': -signal.SIGTERM,
'signal': "SIGTERM",
'event': 'Process exited',
'timestamp': mocker.ANY,
'level': 'info',
'logger': 'supervisor'
} in captured_logs
mock_client.task_instances.finish.assert_called_once_with(
id=TI_ID, state=TerminalTIState.FAILED, when=mocker.ANY
)
kaxil
force-pushed
the
handle-supervisor-signals
branch
from
December 9, 2024 20:17
691d183 to
3f1a533
Compare
Member
Author
|
Parking this for now to work on #44481. If someone wants to take it (and propagating signals to subprocess & its childrens) on, go for it |
Contributor
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions. |
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As part of AIP-72, this PR introduces proper signal handling for the supervisor process. The supervisor now intercepts
SIGTERMsignals to ensure that child processes (task processes) are terminated gracefully.Without signal handling, terminating the supervisor process (e.g., via
kill -TERM) could leave child processes running as orphaned tasks. This change ensures that when the supervisor is stopped, all managed subprocesses are also terminated cleanly.Sample Output when Superviser receives SIGTERM with (
kill -TERM 138):vs without signal handling:
A key difference is in first case the task is also set to
failedstate as it should while before it kept the TI asrunning^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named
{pr_number}.significant.rstor{issue_number}.significant.rst, in newsfragments.