# PR #22103 完整报告

- 仓库：`sgl-project/sglang`
- 标题：Fix killall_sglang missing the main sglang serve process
- 合并时间：2026-04-04 18:43
- 原文链接：http://prhub.com.cn/sgl-project/sglang/pull/22103

---

# 执行摘要
本次 PR 修复了 CI 清理脚本 `killall_sglang` 无法匹配主服务器进程 `sglang serve` 的问题，通过修改正则表达式确保进程被正确杀死，避免端口占用残留。变更简单但关键，提升了 CI 稳定性。

# 功能与动机
`killall_sglang` 脚本用于在 CI 测试后清理 SGLang 进程，但原有正则模式仅匹配子进程（如 `sglang::*`），而主进程命令行格式为 `/usr/local/bin/python3 /usr/local/bin/sglang serve ...`，导致主进程遗漏。这会造成 HTTP 端口占用，影响后续测试运行。PR body 明确指出：“The root process (which owns the uvicorn HTTP server and the listening port) is the only one missed.”

# 实现拆解
仅修改一个文件：`python/sglang/cli/killall.py`。

关键变更：将正则表达式从
```python
r"sglang::|sglang\\.launch_server|sglang\\.bench|sglang\\.data_parallel|sglang\\.srt|sgl_diffusion::"
```
更新为
```python
r"sglang::|sglang\\.launch_server|sglang\\.bench|sglang\\.data_parallel|sglang\\.srt|sgl_diffusion::|sglang serve"
```
添加 `|sglang serve` 以匹配主进程。

# 评论区精华
reviewer gemini-code-assist[bot] 提出两点重要反馈：
> “Please update the shell script as well to ensure local cleanup works as expected.”
> “consider if other CLI subcommands like `sglang bench` should be included; the current regex matches `sglang.bench` (with a dot) for `python -m`, but misses the CLI wrapper `sglang bench` (with a space).”

这揭示了脚本间不一致和子命令覆盖不全的潜在问题，但本次 PR 未采纳这些建议。

# 风险与影响
- **风险**：若未同步更新 shell 脚本 `scripts/killall_sglang.sh`，本地环境可能清理不彻底；正则仍可能遗漏其他 CLI 子命令（如 `sglang bench` 带空格形式）。
- **影响**：CI 测试后端口释放更可靠，减少因进程残留导致的失败；对核心服务无影响。

# 关联脉络
从近期历史 PR 看，多个 PR 涉及 CI 稳定性修复（如 #22083 修复死锁、#21735 修复内存泄漏），本次 PR 是这一趋势的延续，聚焦于进程清理环节。与 #15562（添加使用统计）等 PR 无直接关联，但共同维护了测试环境的健壮性。