mirror of
https://github.com/rclone/rclone.git
synced 2024-11-25 17:57:44 +08:00
vfs: fix deadlock between RWFileHandle.close and File.Remove - fixes #2857
Before this change we took the locks file.mu and file.muRW in an inconsistent order - after the change we always take them in the same order to fix the deadlock.
This commit is contained in:
parent
13387c0838
commit
2cfe2354df
|
@ -444,19 +444,19 @@ func (f *File) Remove() error {
|
|||
if f.d.vfs.Opt.ReadOnly {
|
||||
return EROFS
|
||||
}
|
||||
f.mu.Lock()
|
||||
f.muRW.Lock()
|
||||
f.muRW.Lock() // muRW must be locked before mu to avoid
|
||||
f.mu.Lock() // deadlock in RWFileHandle.openPending and .close
|
||||
if f.o != nil {
|
||||
err := f.o.Remove()
|
||||
if err != nil {
|
||||
fs.Errorf(f, "File.Remove file error: %v", err)
|
||||
f.muRW.Unlock()
|
||||
f.mu.Unlock()
|
||||
f.muRW.Unlock()
|
||||
return err
|
||||
}
|
||||
}
|
||||
f.muRW.Unlock()
|
||||
f.mu.Unlock()
|
||||
f.muRW.Unlock()
|
||||
|
||||
// Remove the item from the directory listing
|
||||
f.d.delObject(f.Name())
|
||||
|
|
Loading…
Reference in New Issue
Block a user