Skip to content

Commit 2d6df29

Browse files
ovaistariqclaude
andcommitted
fix: Address race condition in generation handling after sealDir
Move the generation load to immediately after sealDir() returns but before reacquiring dh.mu. This ensures we capture the generation at the point when sealDir completes, avoiding a race where another thread could call sealDir() between our unlock and the generation load. The sequence is now: 1. Unlock dh.mu 2. Call sealDir() 3. Load generation (while dh.mu is still unlocked) 4. Reacquire dh.mu 5. Update dh.generation This ensures we get the most accurate generation value while still avoiding the deadlock. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent fa72b28 commit 2d6df29

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

core/dir.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,9 +636,11 @@ func (dh *DirHandle) listObjectsFlat() (start string, err error) {
636636
// We must release dh.mu before calling sealDir to avoid deadlock
637637
dh.mu.Unlock()
638638
dh.inode.sealDir()
639+
// Reload generation immediately after sealDir completes to get accurate state
640+
currentGen := atomic.LoadUint64(&dh.inode.dir.generation)
639641
dh.mu.Lock()
640642
// Update our generation to match the new state
641-
dh.generation = atomic.LoadUint64(&dh.inode.dir.generation)
643+
dh.generation = currentGen
642644
}
643645

644646
dh.inode.mu.Unlock()

0 commit comments

Comments
 (0)