Title: fix(git-host): macOS 上只剩未回收僵尸进程的进程组也能正常结束 by xiaoyumuxi · Pull Request #63 · Lithe-IDEA/Lithe-core-rust · GitHub
Open Graph Title: fix(git-host): macOS 上只剩未回收僵尸进程的进程组也能正常结束 by xiaoyumuxi · Pull Request #63 · Lithe-IDEA/Lithe-core-rust
X Title: fix(git-host): macOS 上只剩未回收僵尸进程的进程组也能正常结束 by xiaoyumuxi · Pull Request #63 · Lithe-IDEA/Lithe-core-rust
Description: 关联 Issue / Linked issue Closes 1lck/Lithe-IDEA#2017 PR 类型 / Type fix:缺陷修复 改动说明 / What changes 背景 / Why #2017:lithe-platform-tests 的 lsp_process::terminating_a_language_server_ends_the_processes_it_started 在 macOS 上不稳定。在 main 上连续运行 15 次,失败 8 次。报错是: a terminated server is disposed: CoreError { code: ProcessFailed, message: "Language-server process tree did not exit.", details: Some("Operation not permitted (os error 1)") } 原因在 git-host 的 Unix 进程组: ProcessTree::terminate 先调用 Group::kill,也就是 kill(-pgid, SIGKILL),再轮询进程组里是否还有进程。 Group::kill 只把 ESRCH(组里没有进程)当作正常,其他错误一律返回,terminate 随即失败,不再等待。 在 macOS 上,如果组里的进程都已经退出、但还没被父进程回收(都是僵尸进程),kill(-pgid, …) 返回 EPERM,不是 ESRCH。等它们被回收后,才返回 ESRCH。我用一个小程序在本机确认过:killpg 0 -> EPERM,killpg SIGKILL -> EPERM,回收后 -> ESRCH。 语言服务器的 dispose 在根进程被回收后调用 tree.terminate。这时根进程启动的 runtime 子进程也已经被杀掉,正在等新的父进程 launchd 回收。如果正好落在这个时间窗口里,就会出现上面的报错。 这不只是测试的问题。生产代码走的是同一条路径: lsp-engine 的 destroy 会把这个错误返回给调用方,会话留在注册表里不会删除。启动失败时的清理路径也一样。 关闭 SSH 远程会话时,tree.kill 和 tree.terminate 会误报失败,写出 remote.session.cleanup_failed 的 WARN 日志。 改动 / Changes rust/crates/git-host/src/lib.rs(Unix 的 Group) kill:EPERM 也返回 Ok。EPERM 表示组里没有一个进程接受这个信号:要么在 macOS 上都是还没回收的僵尸进程,要么属于其他用户。两种情况下都没有别的信号可以发。是否真的结束,交给 ProcessTree::terminate 在截止时间内等待判断;如果进程一直不消失,terminate 照常返回 TimedOut。 has_live_processes:行为不变,EPERM 仍然算作"还有进程",所以僵尸进程在被回收之前仍然算在组里。只改了注释:原来只写了"属于其他用户",补上 macOS 的僵尸进程。 rust/crates/platform-tests tests/platform/process_tree.rs:新增 #[cfg(unix)] 测试 a_unix_tree_of_exited_unreaped_processes_ends_without_error。 启动一个 Mode::Hold 夹具,用 tree.kill() 杀掉。 用 waitid(P_PID, …, WEXITED | WNOWAIT) 等到它退出,但不回收,确定它已经是僵尸进程。这一步在辅助线程里阻塞,主线程用 recv_timeout(DEADLINE) 等待,有明确的截止时间。 再调用一次 tree.kill(),断言返回 Ok。在 macOS 上,修复前这里返回 EPERM。 在后台线程回收根进程,断言 tree.terminate(DEADLINE) 返回 Ok,根进程是被信号结束的。 这个测试不依赖时间窗口:组里只剩僵尸进程的状态是确定构造出来的,不靠竞争条件。Linux 允许给僵尸进程发信号,所以这个测试在 Linux 上修复前后应当都通过(没有实测);所有 Unix 平台的预期相同,没有用 cfg! 区分。 Cargo.toml:加 [target.'cfg(unix)'.dev-dependencies] libc = "0.2",测试要调用 waitid。Cargo.lock 随之更新,没有引入新版本的 crate。 不在本 PR 范围内 / Out of scope Windows 用 Job 对象结束进程树,不走这段代码,不受影响。 #62(#2009 的修复)的验证说明里提到了这个不稳定的测试,那个 PR 没有改动这里的代码。 类型专属:fix 复现与根因 复现:在 main(6a14126)上反复运行 cargo test --manifest-path rust/Cargo.toml -p lithe-platform-tests,15 次中失败 8 次。 根因:见上方"背景"。Group::kill 的错误处理来自 git-host 引入 ProcessTree 的时候,没有考虑到 macOS 对只剩僵尸进程的进程组返回 EPERM。 影响平台:macOS。Linux 应当不受影响(没有实测):Linux 允许给僵尸进程发信号,kill 返回成功。Windows 不走这段代码。 检查项 已先写回归测试,确认它修复前失败、修复后通过。 测试路径:rust/crates/platform-tests/tests/platform/process_tree.rs 中的 a_unix_tree_of_exited_unreaped_processes_ends_without_error。 修复前:只撤回 git-host 的修改再运行,测试在第二次 tree.kill() 处失败: a tree whose processes all exited is killed again without error: Os { code: 1, kind: PermissionDenied, message: "Operation not permitted" } 修复后:通过。整个 lithe-platform-tests 连续运行 20 次,20 次全部通过,包括原来不稳定的 lsp_process::terminating_a_language_server_ends_the_processes_it_started。 [N/A] 手动复现:已经自动化。 已检查全部调用方:Group::kill 只通过 ProcessTree::kill 和 ProcessTree::terminate 调用。它们的调用方有: lsp-transport/process.rs 的 terminate_native 和 dispose; workspace/sessions.rs 的 SSH 会话清理和 reap。 这些调用方遇到 EPERM 时原来都会报失败或写 WARN,修复后都不再误报。进程真的没有结束时,terminate 仍然返回 TimedOut。 另一平台:Windows 不走这段代码。Windows 目标的 clippy 已通过。 只改了修复所需的代码。 [N/A] Agent Note:Core 仓库没有 .agents/notes/implemented/bug-fix/。这个约束写在 Group::kill 的注释和回归测试里。 范围检查 / Scope checks 功能矩阵:N/A,没有新增宿主能力。 插件归属:不涉及任何具体插件,测试只用 lithe-platform-fixture 夹具。 UI / i18n:N/A,没有界面文字。 统一日志系统:没有新增或改动日志事件。修复后,SSH 会话清理不再误写 remote.session.cleanup_failed。 逻辑归属:全部在 Rust Core。 性能与内存:没有新增进程、线程或缓存,也没有新增轮询;terminate 原有的轮询不变。 设置:N/A。 插件契约:N/A,没有改插件契约、能力版本、插件函数协议或宿主方法。 发行包与资源:N/A,没有新增运行时资源。 无用代码:没有。 验证 / Verification 本机为 Apple M4,Rust 1.100.0。 命令或操作 平台 结果 cargo fmt --manifest-path rust/Cargo.toml --all -- --check macOS arm64 通过 scripts/rust-core/verify-rust-core-comments.sh macOS arm64 通过 node scripts/rust-core/verify-platform-tests.mjs macOS arm64 通过 cargo test --manifest-path rust/Cargo.toml --workspace --features lithe-remote/server --no-fail-fast macOS arm64 通过:2106 passed,0 failed cargo test --manifest-path rust/Cargo.toml -p lithe-platform-tests,连续 20 次 macOS arm64 20 次全部通过(main 上 15 次失败 8 次) 撤回 git-host 的修改后运行新测试 macOS arm64 按预期失败,输出见上方 cargo clippy --manifest-path rust/Cargo.toml --workspace --all-targets -- -D warnings macOS arm64 通过 cargo clippy --manifest-path rust/Cargo.toml --workspace --all-targets --target x86_64-pc-windows-msvc -- -D warnings macOS 交叉检查 Windows 目标 通过 未能执行的检查和原因: 没有在 Linux 上运行新测试。按 Linux 内核的行为,它在修复前后都应通过;PR 的 Linux CI 会运行它。 没有在 Windows 上运行。Windows 不走这段代码,PR 标记 ready 后 CI 会运行 lithe-platform-tests。 提交前确认 / Final checks 分支从最新 main(6a14126)创建,目标分支 main。不依赖 #62。 以 Draft 提交,本地验证已通过。 没有无关改动、构建产物、凭据或个人路径。 本次验证没有启动 Lithe 应用,没有进程残留。
Open Graph Description: 关联 Issue / Linked issue Closes 1lck/Lithe-IDEA#2017 PR 类型 / Type fix:缺陷修复 改动说明 / What changes 背景 / Why #2017:lithe-platform-tests 的 lsp_process::terminating_a_language_server_ends_the_processe...
X Description: 关联 Issue / Linked issue Closes 1lck/Lithe-IDEA#2017 PR 类型 / Type fix:缺陷修复 改动说明 / What changes 背景 / Why #2017:lithe-platform-tests 的 lsp_process::terminating_a_language_server_ends_the_processe...
Opengraph URL: https://github.com/Lithe-IDEA/Lithe-core-rust/pull/63
X: @github
Domain: github.com
IPv4 address: 140.82.113.4
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:83e35398-02e1-4fd6-99c0-63c77e02f223 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 8FD2:130575:6EFA6:8EFD4:6B076948 |
| html-safe-nonce | 36d2ec38856f9e56fbb8d7ba999eacd01ca558053bd399aa1b94f58a839816c8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RkQyOjEzMDU3NTo2RUZBNjo4RUZENDo2QjA3Njk0OCIsInZpc2l0b3JfaWQiOiI3Njc4ODE0NTc2ODEyOTc2NDU2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 38d30e9a9fd8f201fb314fe50f89f8260c9d5531147fe4c251e560263f94e5fc |
| hovercard-subject-tag | pull_request:5333310875 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/Lithe-IDEA/Lithe-core-rust/pull/63/files |
| twitter:image | https://avatars.githubusercontent.com/u/145102356?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/145102356?s=400&v=4 |
| og:image:alt | 关联 Issue / Linked issue Closes 1lck/Lithe-IDEA#2017 PR 类型 / Type fix:缺陷修复 改动说明 / What changes 背景 / Why #2017:lithe-platform-tests 的 lsp_process::terminating_a_language_server_ends_the_processe... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 59b8f5d72ef6b72449d99daafd74abe56273d30f4491cc421870d3c1bcc07535 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/Lithe-IDEA/Lithe-core-rust git https://github.com/Lithe-IDEA/Lithe-core-rust.git |
| octolytics-dimension-user_id | 340144206 |
| octolytics-dimension-user_login | Lithe-IDEA |
| octolytics-dimension-repository_id | 1449354685 |
| octolytics-dimension-repository_nwo | Lithe-IDEA/Lithe-core-rust |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1449354685 |
| octolytics-dimension-repository_network_root_nwo | Lithe-IDEA/Lithe-core-rust |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 2d876643548d19018f1accd48f914fec9bce9184 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | no-cache |
Viewport: width=device-width