EffectFlock heartbeat never refreshes, so locks held over 60 s can be broken
维护者通常 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
- Hold a lock with
flock.acquire(key)for more than 20 s. - Watch
<lock dir>/heartbeat: its mtime never moves past the time the lock was taken, whileHEARTBEAT_MSis 20 s. - After 60 s,
isStalereports the held lock as stale, so a secondacquire(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
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
anomalyco/opencode 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
anomalyco/opencode#51159 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
查看 anomalyco/opencode 的全部 Issue
相似的 Issue
-
bug
难度 1/5 1 小时以内 新手友好度 88/100
StabilityNexus/Fate-EVM-Frontend#153 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
code-yeongyu/oh-my-openagent#9039 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 84/100
Tencent/teamai-cli#862 ·
维护者通常 1 天内回复
-
bug good first issue hacktoberfest redis
难度 2/5 1-3 小时 新手友好度 88/100
libredb/libredb-studio#1164 ·
维护者通常 1 天内回复
-
flake
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复