Skip to content

Commit

Permalink
vfs: Ignore ECLOSED in Setattr when truncating file handles
Browse files Browse the repository at this point in the history
Before this change file handles could get closed while the truncate
the file handles loop was running.

This would mean that ocassionally an ECLOSED (which is translated into
EBADF by cmd/mount) would spuriously be returned if Release happened
to happen in the middle of a Truncate call (Setattr called with
size=0).

This change ignores the ECLOSED while truncating file handles.

See: https://forum.rclone.org/t/writes-to-wasabi-mount-failing-with-bad-file-descriptor-intermittently/26321
  • Loading branch information
ncw committed Sep 28, 2021
1 parent 5b6bcfc commit 0902e5c
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions vfs/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -746,18 +746,23 @@ func (f *File) Truncate(size int64) (err error) {
copy(writers, f.writers)
f.mu.Unlock()

// FIXME: handle closing writer

// If have writers then call truncate for each writer
if len(writers) != 0 {
var openWriters = len(writers)
fs.Debugf(f.Path(), "Truncating %d file handles", len(writers))
for _, h := range writers {
truncateErr := h.Truncate(size)
if truncateErr != nil {
if truncateErr == ECLOSED {
// Ignore ECLOSED since file handle can get closed while this is running
openWriters--
} else if truncateErr != nil {
err = truncateErr
}
}
return err
// If at least one open writer return here
if openWriters > 0 {
return err
}
}

// if o is nil it isn't valid yet
Expand Down

0 comments on commit 0902e5c

Please sign in to comment.