Repository navigation
[Core] Kill local processes only after the SIGTERM drain deadline has passed - #68457
Merged
rueian merged 1 commit intoNov 25, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces a mechanism to ensure that a node's drain deadline has strictly passed in wall-clock time before shutting down the node. It adds a helper function _wait_until_past_drain_deadline in python/ray/_private/node.py that sleeps for a small margin (10ms) past the deadline, preventing race conditions where a node's termination is incorrectly recorded as EXPECTED_TERMINATION instead of preempted. Corresponding unit tests have been added and updated in python/ray/tests/test_draining.py to verify this behavior. There are no review comments to address, and the implementation looks solid.
… passed When `ray start --block` drains on SIGTERM and the node is still busy at the end of RAY_GRACEFUL_SHUTDOWN_DRAIN_TIMEOUT_S, it killed the raylet at about the same millisecond as the drain deadline. The raylet only records AUTOSCALER_DRAIN_PREEMPTED if the deadline is strictly in the past, so the node was often recorded as EXPECTED_TERMINATION and task retries were counted against max_retries. Wait until wall-clock time is a small margin past the deadline before killing local processes. The wait is capped so that a backwards clock jump cannot stall teardown. Closes ray-project#68304. Signed-off-by: zhangsikai123 <[email protected]>
zhangsikai123
force-pushed
the
fix-sigterm-drain-deadline-68304
branch
from
November 22, 2026 13:21
4a7f298 to
bc6c368
Compare
rueian
approved these changes
Nov 25, 2026
rueian
left a comment
Contributor
There was a problem hiding this comment.
LGTM. thanks @zhangsikai123
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.
Why are these changes needed?
Closes #68304.
On SIGTERM,
ray start --blockdrains the local node withDRAIN_NODE_REASON_PREEMPTIONand a deadline ofnow + RAY_GRACEFUL_SHUTDOWN_DRAIN_TIMEOUT_S(#64454). If the node is still busy when that time is up,_drain_node_before_shutdownreturns andkill_all_processes()sends SIGTERM to the raylet right away.The raylet records the node as preempted only if the drain deadline is strictly in the past when it receives SIGTERM (
deadline_timestamp_ms < now,src/ray/raylet/main.cc). The poll loop ends on the monotonic clock at about the same instant as the wall-clock deadline, so the raylet often seesdeadline == nowand recordsEXPECTED_TERMINATION. Owners then count the failed tasks againstmax_retries(TaskManageronly skips the count forAUTOSCALER_DRAIN_PREEMPTED), so #54182 does not take effect for busy nodes.This PR keeps the raylet's rule as it is and fixes the caller: after the poll loop times out, it sleeps until wall-clock time is 10 ms past the deadline it sent, then kills local processes. The extra wait is capped at 1 s so that a backwards wall-clock jump cannot stall teardown. Nothing changes when the raylet exits on its own after draining, because in that case it takes the death reason from the drain request.
Related issue number
Closes #68304
Testing
Unit tests (
python/ray/tests/test_draining.py):_run_drainnow fakes the wall clock in lockstep with the monotonic clock.test_drain_timeout_kills_only_after_deadline(16 cases over timeout and poll interval) checks that a timed-out drain ends strictly after the deadline sent to the GCS, by at most the margin. Without the fix innode.py, all 16 cases fail.test_drain_early_exit_does_not_wait_for_deadlinechecks that an early exit does not wait.test_wait_until_past_drain_deadlinecovers the helper: before, at and after the deadline, and a backwards clock jump.End to end on Kubernetes (minikube, KubeRay v1.6.2,
rayproject/ray:2.60.0,RAY_GRACEFUL_SHUTDOWN_DRAIN_TIMEOUT_S=3, grace period 10 s). A task pinned to each worker keeps the node busy, the worker pods are deleted, and the head reads each node's death reason from the GCS. Both runs mountnode.pyfrom a ConfigMap: the stock 2.60.0 file (same sha256 as the image) or the same file with this patch applied (the hunk applies to 2.60.0 unchanged).Each run deletes 2 busy workers per round, for 15 rounds (30 nodes):
node.pyAUTOSCALER_DRAIN_PREEMPTEDEXPECTED_TERMINATIONWith the stock file, 6 of 30 busy nodes are recorded as
EXPECTED_TERMINATION("received SIGTERM"). With the patch, all 30 are recorded as preempted.Duplicate check
ray start --blockrecords the node death asEXPECTED_TERMINATIONinstead ofAUTOSCALER_DRAIN_PREEMPTED(off-by-one-ms deadline check) #68304 or touches_drain_node_before_shutdownapart from [Core] Drain node on SIGTERM before shutting downray start --block#64454, which introduced it.PREEMPTIONdrain as preempted in the raylet) is intentionally left out; it overlaps with [Core] Option to retry tasks only after node preemption #66901.AI assistance
I used an AI coding assistant (Claude Code) to draft the change, the tests and this description. I reviewed every changed line and ran the tests and the Kubernetes check above myself.
Checks
git commit -s) in this PR.blackandruff(pre-commit versions) on the changed files.🤖 Generated with Claude Code