Skip to content

Commit 914cd97

Browse files
committed
fix: Address race condition in generation handling after sealDir
Now we read the actual generation value after sealDir() returns to ensure we have the correct current generation.
1 parent 394b8f2 commit 914cd97

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

core/dir.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -631,13 +631,11 @@ func (dh *DirHandle) listObjectsFlat() (start string, err error) {
631631
}
632632
} else {
633633
// We must release dh.mu before calling sealDir to avoid deadlock
634-
// Save the current generation before unlocking
635-
currentGen := atomic.LoadUint64(&dh.inode.dir.generation)
636634
dh.mu.Unlock()
637635
dh.inode.sealDir()
638636
dh.mu.Lock()
639637
// Update our generation to match the new state
640-
dh.generation = currentGen + 1 // We know it was incremented in sealDir
638+
dh.generation = atomic.LoadUint64(&dh.inode.dir.generation)
641639
}
642640

643641
dh.inode.mu.Unlock()
@@ -649,6 +647,9 @@ func (dh *DirHandle) listObjectsFlat() (start string, err error) {
649647
// LOCKS_REQUIRED(dh.inode.mu)
650648
func (dh *DirHandle) checkDirPosition() {
651649
// Check if directory structure changed since we last checked
650+
// Note: There's a benign race here where generation could change between
651+
// the load and assignment. This is acceptable as we'll catch it on the
652+
// next operation. The worst case is an unnecessary position reset.
652653
currentGen := atomic.LoadUint64(&dh.inode.dir.generation)
653654
if dh.generation != currentGen {
654655
dh.lastInternalOffset = -1

0 commit comments

Comments
 (0)