Skip to content

vfscache: fix log message growing without bound on repeated write errors - #9776

Merged
ncw merged 1 commit into
rclone:masterfrom
vjymisal0:fix/vfs-cache-write-stale-error
Aug 27, 2026
Merged

ncw merged 1 commit into
rclone:masterfrom
vjymisal0:fix/vfs-cache-write-stale-error

Conversation

@vjymisal0

Copy link
Copy Markdown
Contributor

What is the purpose of this change?

Fixes #4998 — when the VFS cache runs out of space, the error message logged on each retry grows without bound, repeating vfs reader: failed to write to cache file: hundreds of times (243 repeats in the reporter's log).

Root cause

downloader.Write() performs the actual cache write and gets its own error from WriteAtNoOverwrite (nil when the write succeeds). Its deferred kick block then calls kickWaiters(), which returns the downloaders' accumulated lastErr once errorCount exceeds maxErrorCount (or on out-of-space). That stale error was assigned to Write's named return, so:

  1. A write that actually succeeded was reported as failed.
  2. download() wrapped that returned error in vfs reader: failed to write to cache file: %w.
  3. _countErrors stored the newly wrapped error back as lastErr.
  4. The next write repeated the cycle, adding another prefix each time.

Since lastErr is only cleared when a download completes with no error, the loop kept re-wrapping its own message.

The kickWaiters() failure is already logged on the line above, so returning it as this Write's error is redundant as well as the source of the growth.

Was the change discussed in an issue or in the forum before?

#4998, and the linked forum thread.

Checklist

  • I have read the contribution guidelines.
  • I have added tests for all changes in this PR if appropriate.
  • I have added a note to docs/content/changelog.md if appropriate. (n/a — bugfix, changelog is generated from commit messages)
  • I have checked that all the tests pass.

Testing

Added TestDownloaders/WriteDoesNotFailOnStaleError, which puts the downloaders into the state that triggers the bug (errorCount past maxErrorCount, a stale wrapped lastErr, and an undispatched waiter so kickWaiters reaches the error check) and asserts that a successful Write still returns no error. The test output confirms it exercises the real path:

ERROR : potato.txt: vfs cache: too many errors 11/10: last error: vfs reader: failed to write to cache file: no space left on device
ERROR : potato.txt: vfs cache: download write: failed to kick waiters: vfs reader: failed to write to cache file: no space left on device
--- PASS: TestDownloaders/WriteDoesNotFailOnStaleError (0.02s)

go test ./vfs/... passes in full, and gofmt/go vet are clean.

Write() overwrote a successful write's nil error with the stale
lastErr returned by kickWaiters() once the downloader had recorded
too many errors. download() then wrapped that stale error again and
stored it back as the new lastErr, so every subsequent write added
another "vfs reader: failed to write to cache file:" prefix - fixes rclone#4998
@vjymisal0
vjymisal0 requested a review from ncw as a code owner August 16, 2026 09:39
Copilot AI lite review requested due to automatic review settings August 16, 2026 09:39

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@ncw ncw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you - this looks great

@ncw
ncw merged commit efa5e8f into rclone:master Aug 27, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mount: When the cache space is insufficient, repeated strings will be generated in the log file.

3 participants