memory: two processes clearing one crash-left lock guard can remove a live guard

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

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
42/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
领域
backend, testing

调研方向

Start with isGuardHeld in src/memory/index.ts and the existing lock tests; trace how stale guards are judged and removed by path. The approach is undecided, so first compare it with breakStaleLock and define the remaining race before choosing a fix. Done means a deterministic test shows a fresh guard survives when two processes clear the same crash-left guard, and the existing lock tests pass.

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

描述

bug server-memory v2

Problem

The memory server's cross-process lock uses a second exclusive-create file, the guard (<memory file>.lock.break), to order stale-lock breaking and, since #5565 (PR #5623), every release and every newly created lock's confirmation. A guard left behind by a process that crashed while holding it is cleared by whoever finds it older than the stale timeout (30 seconds by default).

That clearing is done by path: the finder opens the guard, judges its age through the handle, and then calls unlink on the guard's path (isGuardHeld in src/memory/index.ts; before #5565 the same stat then unlink in breakStaleLock). Two processes clearing the same crash-left guard at once can therefore remove a live one:

  1. A and B both open the crash-left guard and judge it stale.
  2. A unlinks it.
  3. C (a releasing holder, or a breaker) creates a fresh guard at the same path.
  4. B unlinks the path, deleting C's fresh guard.

C then runs its few guarded file-system calls unguarded, so a breaker can act between a release's token comparison and its removal (the third window of #5565), or two breakers can run at once.

It takes a crash inside a guarded section (a few file-system calls per write), then two processes clearing that guard within the same moment, then a third taking the guard between their two unlinks. The processes run as the same user, so this is a correctness gap, not a security boundary. Raised by Copilot in review of #5623 and declined there as beyond the three windows #5565 names.

Expected behavior

Clearing a guard left by a crash never removes a guard another process has taken since.

Approach

To be decided. Renaming the guard aside and comparing device and inode with the judged file before deleting it, as breakStaleLock does for the lock itself (#5560), removes exactly this interleaving, but putting a mistakenly taken live guard back has its own gap one level down (a create at the guard path while it is aside). Whatever is chosen should say what remains, as the comment above guardPathOf() does today.

Acceptance criteria

  • A deterministic test (no timing dependence): two clearers of one crash-left guard, with a fresh guard created between their removals; the fresh guard survives.
  • The existing lock tests still pass.
主要语言
TypeScript
星标
92k
派生
12k
平均合并
3 小时 46 分钟
30 天内合并 PR
206

环境准备

从这里开始

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

modelcontextprotocol/servers 的其他 Issue

查看 modelcontextprotocol/servers 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

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