Skip to content

fix: serialize same-node inode updates with a per-inode mutex - #18

Merged
mattmattox merged 2 commits into
mainfrom
claude/fix-inode-write-races
Oct 24, 2026
Merged

mattmattox merged 2 commits into
mainfrom
claude/fix-inode-write-races

Conversation

@mattmattox

@mattmattox mattmattox commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Goroutines on one node share cluster locks, so two of them could rewrite one inode at the same time:

Fix: Write, Setattr, Allocate and Setxattr take an in-process mutex per inode (256 stripes) before any cluster lock. I sent the lock order to the #13 session.

Reach: on one FUSE mount, the kernel already serializes write, ftruncate and fallocate per file. The new mount test passes on main too, so it guards the behavior rather than reproducing the bug. Plain syscalls never hit these races. In-process callers can, and so might kernel paths that skip that lock, such as mmap writeback (not verified).

Tests: the two unit tests fail 10/10 on main and pass 10/10 with -race here. Together they add about 10s to the unit tests.

Cost: writes to the same file from one node no longer overlap.

🤖 Generated with Claude Code

mattmattox and others added 2 commits October 24, 2026 13:26
Goroutines on one node share cluster locks, so nothing stopped two of
them from rewriting the same inode at once:
- Two first writes into one fallocated block both zero-filled it, and
  the second wiped the first one's data.
- A write could store its stale copy of the inode over a truncate that
  committed meanwhile, so the file mapped blocks the truncate freed.

Write, Setattr and Allocate now take a striped in-process mutex around
each attempt, and Setxattr (snapshot, clone) holds it for the whole
call. It comes before any cluster lock.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mattmattox
mattmattox merged commit a52ca2c into main Oct 24, 2026
6 checks passed
mattmattox added a commit that referenced this pull request Oct 24, 2026
…ims are confirmed (#22)

Taking a lock is still a read then a write, so two nodes that claim a free
inode lock at the same moment can both hold it. The test does that for 20
files per run and loses one node's write in about 1 file in 150: 4 of 30
runs failed on main and 2 of 30 on #13 before #18 and #20 landed, so #18 is
not the cause. CI runs integration with -short; full runs still include it.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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