Skip to content

fix(monitor): prevent startup crash when helper watcher init fails#15

Merged
jdjingdian merged 2 commits intomainfrom
dev
Mar 24, 2026
Merged

fix(monitor): prevent startup crash when helper watcher init fails#15
jdjingdian merged 2 commits intomainfrom
dev

Conversation

@jdjingdian
Copy link
Copy Markdown
Owner

背景

在 macOS 13 环境下,应用启动阶段会在 HelperToolMonitor.start(changeOccurred:) 必现崩溃。根因是目录监听初始化时,open(..., O_EVTONLY) 失败后仍继续创建 DispatchSource,触发 EXC_BREAKPOINT (SIGTRAP)

变更内容

1) 修复启动崩溃(核心)

  • HelperToolMonitor 中为每个监控目录增加 open 返回值校验,仅在 fd >= 0 时创建 DispatchSource
  • 新增 StartReport,暴露监听初始化结果(可用 source 数量 / 失败信息)。
  • 为失败路径补充日志(目录路径、errno、degraded 状态)。
  • start/stop 生命周期改为幂等,避免重复注册与异常取消。

2) 启动降级策略(保证可用性)

  • RouterService 接入 HelperToolMonitor.start 的返回结果。
  • 当监听全部不可用时,启用低频 fallback 刷新(10s)保持 helperStatus 可更新。
  • 应用重新激活时触发一次即时刷新,减少状态延迟。
  • helperStatus 更新增加去重,降低重复写和竞态风险。

3) OpenSpec 同步与归档

  • fix-macos13-startup-crash 变更任务已完成并归档:
    • openspec/changes/archive/2026-03-24-fix-macos13-startup-crash
  • 同步/更新主规范:
    • openspec/specs/helper-monitor-stability/spec.md
    • openspec/specs/router-service/spec.md

4) 版本信息

  • 更新版本号:
    • MARKETING_VERSION: 2.2.1
    • CURRENT_PROJECT_VERSION: 66

验证

  • 本地构建通过:
    • xcodebuild -project StaticRouteHelper.xcodeproj -scheme "Static Router" -configuration Debug -sdk macosx build CODE_SIGNING_ALLOWED=NO
  • OpenSpec 任务完成:12/12

影响评估

  • 仅在监听不可用时才启用 fallback 轮询,正常路径无额外轮询开销。
  • 不涉及 XPC 协议变更,不影响既有 helper 安装/通信接口。
  • 主要收益:修复 macOS 13 启动崩溃,提升启动期稳定性与状态可观测性。

Guard HelperToolMonitor source creation with valid file descriptors
and expose start health for degraded monitoring paths.
Enable RouterService fallback status polling and refresh on app
activation when filesystem watchers are unavailable.
Mark OpenSpec tasks done, sync updated specs, and archive
2026-03-24-fix-macos13-startup-crash.
@jdjingdian jdjingdian merged commit 863f878 into main Mar 24, 2026
1 check passed
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.

1 participant