Commit e81f3db
fix: Eliminate critical race conditions in generation validation
This commit fixes critical race conditions that cause data corruption
and inconsistent filesystem state (confidence score: 0/5).
**Critical Issues Fixed:**
1. **Data race at line 358**: Was capturing inode.dir.generation
without holding inode.mu lock. Atomic operations alone don't
prevent races - we need to hold the lock to read protected state.
2. **Broken validation logic at line 372**: Checking if
inode.generation == inodeGen after potential seal was logically
flawed. It couldn't distinguish "we sealed it" from "someone else
sealed it", leading to incorrect gap marking.
3. **Always-failing check at line 382**: Checking if generation == gen
after sealDir() would ALWAYS fail because sealDir() increments
generation by 1. This meant gaps were NEVER marked in the
inode==parent case, causing filesystem inconsistency.
4. **Race window in lines 365-372**: Complex pre-seal checks created
multiple race windows where concurrent modifications could result
in marking gaps even though we didn't seal the directory.
**Solution:**
Reverted to the simple, correct approach:
- For inode != parent: Seal unconditionally, only validate parent
generation for gap marking consistency
- For inode == parent: Seal and mark gap while holding lock (no
validation needed)
- No pre-seal generation checks that create race windows
- No post-seal validation of inode state (we own the lock during seal)
This eliminates all race conditions and logical errors while
maintaining correct concurrency semantics.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>1 parent f32ac70 commit e81f3db
1 file changed
+4
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
355 | 355 | | |
356 | 356 | | |
357 | 357 | | |
358 | | - | |
359 | 358 | | |
360 | 359 | | |
361 | 360 | | |
362 | 361 | | |
363 | | - | |
364 | | - | |
365 | | - | |
366 | | - | |
367 | | - | |
| 362 | + | |
368 | 363 | | |
369 | 364 | | |
370 | 365 | | |
371 | 366 | | |
372 | | - | |
| 367 | + | |
373 | 368 | | |
374 | 369 | | |
375 | 370 | | |
376 | 371 | | |
377 | 372 | | |
378 | 373 | | |
379 | | - | |
380 | 374 | | |
381 | | - | |
382 | | - | |
383 | | - | |
384 | | - | |
| 375 | + | |
| 376 | + | |
385 | 377 | | |
386 | 378 | | |
387 | 379 | | |
| |||
0 commit comments