Skip to content

fix(hermes): terminate the Gateway process tree on Windows - #1383

Open
dvd233 wants to merge 1 commit into
TencentCloud:feat/server_teamfrom
dvd233:fix/windows-gateway-process-tree
Open

dvd233 wants to merge 1 commit into
TencentCloud:feat/server_teamfrom
dvd233:fix/windows-gateway-process-tree

Conversation

@dvd233

@dvd233 dvd233 commented Sep 16, 2026

Copy link
Copy Markdown

Description | 描述

Fixes #1381.

supervisor.shutdown() 依赖 os.killpg 做进程组终止,但 os.killpg 在 Windows 上不存在。抛 AttributeError 后落到 proc.terminate(),只杀掉 sh/pnpm 包装层,杀不到它启动的 node.exe 子进程 —— 于是 Gateway 在会话结束后残留,继续占用 8420 端口,下个会话撞到被占用的端口。

修复:新增平台感知的 _terminate_tree——

  • POSIX:照旧 os.killpg 信号整个进程组(行为不变)。
  • Windows:对包装层 PID 用 taskkill /F /T(/T 走子进程树)。/F 是必须的——实测发现温和的 taskkill /T 只对有窗口消息循环的进程有效,而无窗口的 node.exe 会被跳过(报 "can only be terminated forcefully")。

Related Issue | 关联 Issue

Fixes #1381

Change Type | 修改类型

  • Bug fix | Bug 修复

Self-test Checklist | 自测清单

  • Verified locally | 本地验证通过
  • No existing features affected | 无影响现有功能

Additional Notes | 其他说明

  • 本机 Windows 11 实测:确认 os.killpg 不存在;确认 taskkill /F /T 能终止"父进程 + 其子进程"的整棵树(rc=0,双方进程均消失);确认温和的 taskkill /T(不带 /F)对无窗口进程无效。
  • POSIX 路径行为完全不变(仍 killpg SIGTERM/SIGKILL + proc.wait 超时兜底)。

本 PR 在 AI 编码助手辅助下完成;Windows 行为实测、语法检查均由本人本地执行。

supervisor.shutdown() relied on os.killpg, which does not exist on
Windows; the AttributeError fell through to proc.terminate(), which only
kills the sh/pnpm wrapper and leaves the node.exe listener holding port
8420 after the session ends.

Add a platform-aware _terminate_tree: POSIX signals the whole process
group (unchanged), Windows uses taskkill /F /T against the wrapper PID —
the /T tree walk is required because the wrapper's exit orphans the node
child, and /F is required because the windowless node process ignores
the graceful form.

Verified on Windows 11: os.killpg absent, taskkill /F /T terminates the
parent and the orphaned child.

Fixes TencentCloud#1381
@Maxwell-Code07

Copy link
Copy Markdown
Collaborator

Thank you so much for your attention and contribution! We will arrange an internal review for this PR shortly, and all feedback will be shared right here in the discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Windows: plugin-managed Gateway survives session exit (node.exe keeps port 8420, supervisor.py uses os.killpg)

2 participants