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

Đang mở
#5,624 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
42/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
node.js, typescript
Lĩnh vực
backend, testing

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.
Ngôn ngữ chính
TypeScript
Star
92k
Fork
12k
Merge trung bình
3 giờ 46 phút
Pull request đã merge (30 ngày)
206

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của modelcontextprotocol/servers

Tất cả issue của modelcontextprotocol/servers

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.