Skip to content

Commit d06a02a

Browse files
committed
Fix a race condition on parallel lookup of removed files
Test case: 1) mount the FS 2) create a file in it 3) remove that file using any other means (another parallel geesefs, aws-cli, Web UI...) 4) wait 1 minute (cache TTL) 5) without first re-reading the directory with that file, run: `(for i in {1..20}; do echo "ls -l mnt/dir/abc &"; done; echo wait) | bash` where mnt/dir/abc is your deleted file 6) observe geesefs crash with `panic: dir.removeName(abc) but child not found: 2`
1 parent a2337a0 commit d06a02a

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

internal/dir.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,10 +926,18 @@ func (parent *Inode) removeAllChildrenUnlocked() {
926926
}
927927

928928
// LOCKS_EXCLUDED(parent.fs.mu)
929+
// LOCKS_EXCLUDED(parent.mu)
930+
// LOCKS_EXCLUDED(inode.mu)
929931
func (parent *Inode) removeChild(inode *Inode) {
930932
parent.mu.Lock()
931933
defer parent.mu.Unlock()
932934

935+
l := len(parent.dir.Children)
936+
i := sort.Search(l, parent.findInodeFunc(inode.Name))
937+
if l <= 2 || i >= l || parent.dir.Children[i] != inode {
938+
return
939+
}
940+
933941
inode.mu.Lock()
934942
defer inode.mu.Unlock()
935943

0 commit comments

Comments
 (0)