Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix deadlock under concurrent truncate and releases #3457

Merged
merged 2 commits into from
Apr 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion pkg/vfs/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,14 @@ func (v *VFS) newHandle(inode Ino) *handle {
func (v *VFS) findAllHandles(inode Ino) []*handle {
v.hanleM.Lock()
defer v.hanleM.Unlock()
return v.handles[inode]
hs := v.handles[inode]
if len(hs) <= 1 {
return hs
}
// copy hs so it will not be modified by releaseHandle
hs2 := make([]*handle, len(hs))
copy(hs2, hs)
return hs2
}

func (v *VFS) findHandle(inode Ino, fh uint64) *handle {
Expand Down
2 changes: 2 additions & 0 deletions pkg/vfs/vfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package vfs
import (
"encoding/json"
"runtime"
"sort"
"sync"
"syscall"
"time"
Expand Down Expand Up @@ -438,6 +439,7 @@ func (v *VFS) Truncate(ctx Context, ino Ino, size int64, opened uint8, attr *Att
return
}
hs := v.findAllHandles(ino)
sort.Slice(hs, func(i, j int) bool { return hs[i].fh < hs[j].fh })
for _, h := range hs {
if !h.Wlock(ctx) {
err = syscall.EINTR
Expand Down