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

EffectFlock heartbeat never refreshes, so locks held over 60 s can be broken

未关闭 适合新手
#51,179 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
typescript

调研方向

先阅读 packages/core/src/util/effect-flock.ts,重点关注由 EffectFlock.acquire 启动的 heartbeat,以及 isStale 如何对其进行评估。然后检查 packages/core/src/npm.ts 和 packages/core/src/repository-cache.ts 中 lock 的调用位置。完成的标准是:持有中的 lock 的 heartbeat 在每个间隔推进,并且回归场景在 60 秒后不再将其视为过期。

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

描述

Description

EffectFlock.acquire never refreshes its heartbeat, so any lock held longer than 60 s looks abandoned and another process can break it while the holder is still working.

The heartbeat is started like this (packages/core/src/util/effect-flock.ts):

yield* fs
  .utimes(handle.heartbeatPath, new Date(), new Date())
  .pipe(Effect.ignore, Effect.repeat(Schedule.spaced(HEARTBEAT_MS)), Effect.forkScoped)

Effect.repeat runs the same effect again on every tick, and the two Dates were created once when that effect was built. So every tick sets the heartbeat back to the acquisition time. isStale treats a heartbeat older than STALE_MS (60 s) as a dead holder, so from 60 s after acquisition the lock can be taken by the next process that asks for it.

Holders that can run past 60 s include the npm install lock (npm-install:<dir> in packages/core/src/npm.ts) and the repository cache clone lock (packages/core/src/repository-cache.ts). If a second process asks for the same key during a slow install or clone, both proceed in the same directory.

Plugins

None needed.

OpenCode version

dev at 0f549842ee (also 1.18.32)

Steps to reproduce
  1. Hold a lock with flock.acquire(key) for more than 20 s.
  2. Watch <lock dir>/heartbeat: its mtime never moves past the time the lock was taken, while HEARTBEAT_MS is 20 s.
  3. After 60 s, isStale reports the held lock as stale, so a second acquire(key) from another process breaks it and succeeds.

A regression test for step 2 is in the linked PR: with the lock held, backdate the heartbeat, advance the clock one interval, and check the heartbeat's age. Today it keeps the acquisition time.

Screenshot and/or share link

n/a

Operating System

Linux

Terminal

n/a

主要语言
TypeScript
星标
210k
派生
27.8k
平均合并
8 小时 1 分钟
30 天内合并 PR
357

环境准备

从这里开始

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

anomalyco/opencode 的其他 Issue

查看 anomalyco/opencode 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

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