Skip to content

[CI] Reclaim leaked /dev/shm segments on server startup - #28089

Merged
Kangyan-Zhou merged 4 commits into
sgl-project:mainfrom
Kangyan-Zhou:shm-stale-cleanup
Jun 15, 2026
Merged

Kangyan-Zhou merged 4 commits into
sgl-project:mainfrom
Kangyan-Zhou:shm-stale-cleanup

Conversation

@Kangyan-Zhou

@Kangyan-Zhou Kangyan-Zhou commented Jun 12, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

CI jobs tear sglang down with SIGKILL (kill_process_tree, PR_SET_PDEATHSIG), which skips every Python-level shared-memory unlink path (finally blocks, atexit, the multiprocessing resource_tracker — itself SIGKILLed as part of the tree). Leaked psm_* segments accumulate across jobs in long-lived runner containers until /dev/shm (1 GiB on 1-GPU runners) is 100% full, and the next scheduler init dies with:

Fatal Python error: Bus error
RuntimeError: Rank 0 scheduler died during initialization (exit code: -7)

Observed on h100-novita-host3-gpu-2 (failing base-b-test-1-gpu-large on #28076): /dev/shm at 100% with hundreds of multi-MB psm_* segments leaked by earlier SIGKILLed jobs.

Modifications

  • New sglang/srt/utils/stale_shm_cleanup.py:
    • make_shm_name(kind) → sgl_shm_<kind>_<pid>_<rand>, so segments are attributable to their creator process.
    • cleanup_stale_shm() — unlink sgl_shm_* / multi_tokenizer_args_* segments whose creator pid is dead. CI-only (gated on SGLANG_IS_IN_CI): pid-liveness is only a trustworthy ownership signal in single-tenant runner containers; never touches foreign psm_* segments; pid-reuse degrades to under-collection, never to deleting a live segment. Best-effort: never raises, logs failures instead of silently no-oping.
  • All four anonymous SharedMemory(create=True) sites now use pid-stamped names: ShmPointerMMData (mm_utils), ShmRingBuffer (shm_broadcast), ShmSyncBuffer (cuda_ipc_transport_utils), is_in_the_same_node (parallel_state). multi_tokenizer_args_<pid> already embedded the pid.
  • Sweep runs once per CI job from scripts/ci/cuda/ci_install_dependency.sh (right after kill_existing_processes, before installs). The module is import-free and invoked by file path, so it works before sglang is installed.

Checklist

  • Unit tests added (test/registered/utils/test_stale_shm_cleanup.py, registered in base-a-test-cpu), including a call-site binding test for ShmRingBuffer and the run-by-path entry.
  • Cleanup verified end-to-end inside the affected runner container (dead-creator segments removed, live + foreign segments preserved, no-op outside CI, run-by-path with no PYTHONPATH works).

🤖 Generated with Claude Code


CI States

Latest PR Test (Base): ✅ Run #27519180685
Latest PR Test (Extra): ❌ Run #27519180607

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

Kangyan-Zhou and others added 3 commits June 12, 2026 15:21
SGLang tears processes down with SIGKILL (kill_process_tree, PDEATHSIG),
which skips every Python-level shm unlink path. On CI runners the leaked
segments accumulate across jobs until /dev/shm (1 GiB on 1-GPU runners)
fills up and the next scheduler init dies with SIGBUS
("Fatal Python error: Bus error", exit code -7).

Fix: name our anonymous shared-memory segments with the creator pid
(sgl_shm_<kind>_<pid>_<rand>) and sweep dead-creator segments at server
startup. The sweep is gated on SGLANG_IS_IN_CI because pid-liveness is
only a trustworthy ownership signal in single-tenant runner containers.

- mm_utils ShmPointerMMData and shm_broadcast ShmRingBuffer now pass an
  explicit pid-stamped name (multi_tokenizer_args_<pid> already does)
- cleanup_stale_shm() runs at Engine._launch_subprocesses, covering both
  the HTTP server and Engine entrypoints
- unlinks only sgl_shm_* / multi_tokenizer_args_* whose creator pid is
  dead; foreign psm_* segments are never touched

Verified end-to-end inside the h100-novita-host3-gpu-2 runner container.

Co-Authored-By: Claude Fable 5 <[email protected]>
…ymous shm sites

- cleanup_stale_shm never raises (outer guard with logged warning) so a
  sweep failure can't block server startup
- iterdir / unlink failures log warnings instead of silently no-oping;
  only the FileNotFoundError unlink race stays silent
- reject non-positive pids in _creator_pid (os.kill(0/-1, 0) probes
  process groups, not a process)
- convert the two remaining anonymous SharedMemory creators
  (parallel_state is_in_the_same_node, cuda_ipc ShmSyncBuffer) to
  pid-stamped names
- tests: bind the ShmRingBuffer call site to the reclaimable name
  format, use a realistic psm_* foreign segment, cover non-positive pids

Co-Authored-By: Claude Fable 5 <[email protected]>
Run the sweep once per CI job (right after killall, before installs)
instead of at every engine startup:

- the gate reads SGLANG_IS_IN_CI directly so the module is import-free
  and runnable by file path before sglang is installed
- __main__ entry + cuda ci_install_dependency.sh step (best-effort,
  || true)
- engine startup no longer calls the sweep
- tests patch the env var and cover the run-by-path entry

Co-Authored-By: Claude Fable 5 <[email protected]>
@Kangyan-Zhou

Copy link
Copy Markdown
Collaborator Author

/tag-and-rerun-ci

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant