Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

[Bug]: Privileged helper spins at 200% CPU: readabilityHandler is not cleared at EOF

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

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
58/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
macos, swift
领域
devtools

调研方向

Start by locating MonitoredProcessManager and its readabilityHandler for the monitored process output pipe; the issue’s decompiled example identifies the EOF path to inspect. Verify the handler is cleared even when self is gone or outputPipe has changed, and add or run a relevant test if the project has one; done means EOF stops repeated handler calls without affecting a different pipe.

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

描述

fixed-in-next-release macOS
Platform

macOS

Operating system version

macOS 26.6.2

System architecture

ARM64 (M1, M2, etc)

Herd Version

1.28.0

PHP Version

No response

Bug description

After long uptime (~34 days in my case), the privileged helper /Library/PrivilegedHelperTools/de.beyondco.herd.helper sat at a constant ~200% CPU (two full cores), heating the machine. Nothing in Herd's UI indicated a problem, and the helper did not write anything to the system log.

sudo launchctl kickstart -k system/de.beyondco.herd.helper fixed it immediately (CPU dropped to ~0%), and Herd services kept working. So the helper had been stuck in a busy loop, not doing useful work.

Helper binary: universal, sha256 f017ba852a28e939cf43cfcc2f269501165cc5276febea26b0355596639a000e.

Likely cause

I looked at the arm64 slice of the helper to find what could be spinning. In MonitoredProcessManager, the monitored process's output is read through outputPipe.fileHandleForReading.readabilityHandler (installed at 0x10001a118, handler body at 0x10001a220). Decompiled, the handler looks roughly like this:

pipe.fileHandleForReading.readabilityHandler = { [weak self] handle in
    let data = handle.availableData
    if !data.isEmpty {
        if let s = String(data: data, encoding: .utf8) {
            DispatchQueue.main.async { /* append to processLogs */ }
        }
    } else {
        guard let self, let pipe = self.outputPipe else { return }
        pipe.fileHandleForReading.readabilityHandler = nil
    }
}

At EOF, readabilityHandler is invoked repeatedly with empty data until it is set to nil, and each such handler pins one core. This handler clears itself through self.outputPipe, not through the handle it received, so it can stay installed forever:

  1. The owner is gone. weak self is nil, the guard returns, and the handler is never cleared.
  2. The owner now holds a different pipe. After a monitored process is restarted (for example, switching PHP versions or restarting services), outputPipe points to the new pipe. The old handler then clears the new pipe's handler and keeps spinning on its own.

Two stale handlers like this would account for exactly the 200% I saw.

Suggested fix

Clear the handler through the handle passed into the closure, which does not depend on self or on which pipe is current:

} else {
    handle.readabilityHandler = nil
}
Caveat

I did not reproduce the busy loop directly: the helper was already restarted when I analyzed it. The analysis above is based on reading the shipped binary, and it matches the observed symptoms (exactly two cores, long uptime, instant fix after restarting the helper).

Steps to reproduce

Not reliably reproducible on demand. Observed after ~34 days of uptime with Herd services (nginx, dnsmasq, PHP) running and being restarted / PHP versions switched over that period. The code path above suggests: restart or replace a monitored process while its previous output pipe hits EOF.

Relevant log output
$ ps -Ao pid,pcpu,etime,comm -r | head -2
  PID  %CPU     ELAPSED COMMAND
 5373 199.3 34-13:56:30 /Library/PrivilegedHelperTools/de.beyondco.herd.helper
主要语言
没有语言数据
星标
123
派生
1
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

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

beyondcode/herd-community 的其他 Issue

查看 beyondcode/herd-community 的全部 Issue

相似的 Issue

更多 DevTools Issue

把新 issue 发到你的邮箱

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