Skip to content

Fix file-lock double-acquire in ENOENT recovery branch#660

Merged
h0x91b merged 1 commit into
mainfrom
fix/dev3-file-lock-double-acquire
Jun 15, 2026
Merged

Fix file-lock double-acquire in ENOENT recovery branch#660
h0x91b merged 1 commit into
mainfrom
fix/dev3-file-lock-double-acquire

Conversation

@h0x91b

@h0x91b h0x91b commented Jun 15, 2026

Copy link
Copy Markdown
Owner

Summary

  • The mkdir-based file lock (src/bun/file-lock.ts) could be acquired by two processes at once for a brand-new project. The ENOENT recovery branch used mkdirSync(lockDir, { recursive: true }), which is idempotent and never throws EEXIST — so two processes racing through that branch (e.g. desktop app + dev3 remote doing the first write for a new project) could both "acquire" the same lock and corrupt tasks.json via lost updates.
  • Fix: in the ENOENT branch, create only the parent directory recursively, then loop back to retry the atomic non-recursive mkdirSync(lockDir). EEXIST detection is preserved, so exactly one process wins.
  • Backward compatible: the lock path (<filePath>.lock) and its plain-empty-directory shape are unchanged, so older app versions sharing ~/.dev3.0/ keep interoperating and a downgrade is safe.
  • Added a deterministic cross-process repro test (file-lock-enoent-race.test.ts, mocks node:fs to inject a single ENOENT while the lock dir already exists) plus backward-compatibility tests asserting the lock dir is a plain dir acquirable/removable via plain mkdir/rmdir.
  • Decision record 069.

(This PR was prepared by Claude, the AI assistant working on this branch.)

The ENOENT branch recovered with mkdirSync(lockDir, { recursive: true }),
which never throws EEXIST and succeeds on an already-existing dir. Two
processes racing through this branch for a brand-new project could both
acquire the same lock and corrupt tasks.json. Create only the parent dir
and retry the atomic non-recursive mkdir so EEXIST detection holds. Lock
path and on-disk shape are unchanged (older versions stay interoperable).
@h0x91b h0x91b enabled auto-merge (squash) June 15, 2026 10:40
@h0x91b h0x91b merged commit 0cafd18 into main Jun 15, 2026
4 checks passed
@h0x91b h0x91b deleted the fix/dev3-file-lock-double-acquire branch June 15, 2026 10:41
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