diff --git a/python/sglang/srt/disaggregation/decode.py b/python/sglang/srt/disaggregation/decode.py index 4da8bc29b2..3d233172f0 100644 --- a/python/sglang/srt/disaggregation/decode.py +++ b/python/sglang/srt/disaggregation/decode.py @@ -2865,6 +2865,9 @@ class SchedulerDisaggregationDecodeMixin: """A normal scheduler loop for decode worker in disaggregation mode.""" while True: + if self.gracefully_exit: + break + # Pending rooms from the prior cycle can overlap request intake and # the tail of the in-flight decode graph. if not self._engine_paused: @@ -2909,6 +2912,9 @@ class SchedulerDisaggregationDecodeMixin: self.process_batch_result(tmp_batch, tmp_result) while True: + if self.gracefully_exit: + break + # Pending rooms from the prior cycle can overlap request intake and # the tail of the in-flight decode graph. if not self._engine_paused: diff --git a/python/sglang/srt/disaggregation/prefill.py b/python/sglang/srt/disaggregation/prefill.py index 7634a932bd..de1bd2b849 100644 --- a/python/sglang/srt/disaggregation/prefill.py +++ b/python/sglang/srt/disaggregation/prefill.py @@ -666,6 +666,9 @@ class SchedulerDisaggregationPrefillMixin: def event_loop_normal_disagg_prefill(self: Scheduler) -> None: """A normal scheduler loop for prefill worker in disaggregation mode.""" while True: + if self.gracefully_exit: + break + # Receive requests self.ingest_requests() if self._engine_paused: @@ -706,6 +709,9 @@ class SchedulerDisaggregationPrefillMixin: self.result_queue = deque() while True: + if self.gracefully_exit: + break + # Receive requests self.ingest_requests() if self._engine_paused: diff --git a/python/sglang/srt/entrypoints/engine.py b/python/sglang/srt/entrypoints/engine.py index 665eac6f0e..4df8182334 100644 --- a/python/sglang/srt/entrypoints/engine.py +++ b/python/sglang/srt/entrypoints/engine.py @@ -1184,6 +1184,20 @@ class Engine(EngineScoreMixin, EngineBase): weight_cache_daemon_procs, ) + # Non-zero ranks cannot drain on their own: rank 0 stops every TP rank + # via the ShutdownReq broadcast, and the orchestrator's kill timeout is + # the backstop. + if threading.current_thread() is threading.main_thread(): + + def sigterm_handler(signum, frame): + logger.warning( + f"SIGTERM received on node_rank {get_parallel().node_rank}; " + "waiting for the rank-0 ShutdownReq broadcast to stop " + "the schedulers." + ) + + signal.signal(signal.SIGTERM, sigterm_handler) + # A node-local Rust listener owns the health endpoints when present. rust_server_owns_base_port = ( envs.SGLANG_RUST_SERVER.get() and node_hosts_rust_server() diff --git a/python/sglang/srt/entrypoints/http_server.py b/python/sglang/srt/entrypoints/http_server.py index ec0cacf01a..46a6855e9f 100644 --- a/python/sglang/srt/entrypoints/http_server.py +++ b/python/sglang/srt/entrypoints/http_server.py @@ -2862,6 +2862,10 @@ def launch_server( run_detokenizer_process_func=run_detokenizer_process_func, ) + if get_parallel().node_rank >= 1: + # _launch_subprocesses already blocked until the schedulers exited. + return + if envs.SGLANG_RUST_SERVER.get(): # The Rust server serves api-server, tokenizer, and detokenizer, so the # main process has no Python HTTP server / tokenizer manager to run. diff --git a/test/registered/unit/managers/test_disagg_idle_step_counters.py b/test/registered/unit/managers/test_disagg_idle_step_counters.py index 90a769d534..78fc21dfb9 100644 --- a/test/registered/unit/managers/test_disagg_idle_step_counters.py +++ b/test/registered/unit/managers/test_disagg_idle_step_counters.py @@ -217,7 +217,6 @@ class TestSchedulerIdleStepCounters(CustomTestCase): batches[:2] + [None] * idle_iterations + batches[2:] + [None] ) scheduler = self.make_scheduler(schedule) - scheduler.gracefully_exit = False scheduler.future_map = None scheduler.result_queue = deque() scheduler._prepare_mlx_launch = MethodType( @@ -403,6 +402,7 @@ class TestSchedulerIdleStepCounters(CustomTestCase): def make_scheduler(self, schedule): scheduler = Scheduler.__new__(Scheduler) + scheduler.gracefully_exit = False scheduler._engine_paused = False scheduler._sched_idled = False scheduler._prev_step = None