bregctl dev: a detached supervisor can inherit another start's output pipe, hanging parallel installed-dev tests

未关闭
#2,631 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
48/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
rust
领域
cli, testing

调研方向

Start with crates/registry-bregctl/tests/dev_lifecycle.rs and trace Session::start() and run_supervisor() to see how the detached process handles inherited file descriptors. Review the macOS process spawning path and reproduce by running the installed-dev tests in parallel. Done when concurrent starts return within a bound and the regression test passes.

由索引模型根据 Issue 内容生成。

描述

area:breg bug rust

What happens

Running the installed-dev tests in crates/registry-bregctl/tests/dev_lifecycle.rs in parallel can hang one test indefinitely on macOS. The hung test is waiting in Command::output() for EOF on its child's stdout pipe. lsof during a hang showed the write end of that pipe held open by a different test's detached bregctl dev supervisor and the breg server it started, so the read never ends.

Likely cause (medium-high confidence)

On macOS, Rust's standard library creates pipes with pipe() and sets FD_CLOEXEC afterwards, which is not atomic. When two threads call Session::start() at once, one bregctl dev start child can inherit the other thread's pipe write end before FD_CLOEXEC is set. That child then hands the descriptor to its detached supervisor (run_supervisor calls setsid() but keeps inherited descriptors), which keeps it open for the life of the dev environment. The fd numbers matched; the fork itself was not caught.

The same inheritance would affect an operator who starts two dev environments from one parent process, though that is less likely outside tests.

Candidate fixes

  • When detaching the supervisor, close every inherited descriptor above 2 (or reopen 0 to 2 on /dev/null and close the rest).
  • Or spawn the supervisor with posix_spawn and POSIX_SPAWN_CLOEXEC_DEFAULT, passing only the descriptors it needs.

A regression test can start two sessions concurrently and assert that each dev start returns within a bound.

Found while verifying the external record projections branch (feat/breg-external-views).

主要语言
Rust
星标
2
派生
0
平均合并
9 小时 48 分钟
30 天内合并 PR
151

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

registrystack/registry-stack 的其他 Issue

查看 registrystack/registry-stack 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。