Skip to content

vfs: race condition in write cache causes File.Rename to fail #9943

Open

Description

@HarmfulBreeze

Before you start

  • I have searched the forum and the existing issues for this problem.
  • I have tested with the latest beta or stable release and can still reproduce the problem.
  • This is a reproducible bug, not a usage question (questions belong on the forum).

Associated forum post URL

https://forum.rclone.org/t/windows-vfscache-failed-cache-rename-over-an-open-handle-returns-errc-0-success-silently-losing-atomic-temp-rename-saves/54004

What is the problem you are having with rclone?

When editing a file's tags in foobar2000 (a music player), sometimes (quite randomly) rclone throws the following:

2026/09/18 15:50:32 INFO  : <album path>/temp-85B2B722123322D2716935308FE52144.tmp: vfs cache: queuing for upload in 5s
2026/09/18 15:50:32 INFO  : <album path>/01. The Subway.flac: File.Rename failed in Cache: failed to rename in cache: <album path>\temp-85B2B722123322D2716935308FE52144.tmp to <album path>\01. The Subway.flac: rename <album path>\temp-85B2B722123322D2716935308FE52144.tmp <album path>\01. The Subway.flac: Accès refusé.
2026/09/18 15:50:32 INFO  : <album path>/01. The Subway.flac: vfs cache: removed cache file as stale (remote deleted)
2026/09/18 15:50:37 INFO  : <album path>/01. The Subway.flac: Copied (new)
2026/09/18 15:50:37 INFO  : <album path>/01. The Subway.flac: vfs cache: upload succeeded try #1

This effectively results in the file being truncated to 0 inside the mount. The temporary file is kept inside the VFS cache and simply copying it to the mount usually fixes the edited file.

rclone version

rclone v1.75.1

  • os/version: Microsoft Windows 11 Pro 25H2 25H2 (64 bit)
  • os/kernel: 10.0.26200.9457 (x86_64)
  • os/type: windows
  • os/arch: amd64
  • go/version: go1.26.8
  • go/linking: static
  • go/tags: cmount

Operating system

Windows

Which cloud storage system are you using?

Pixeldrain

Output of rclone config redacted

[pixeldrainfs]
type = pixeldrain
api_key = XXX
global.disable_http2 = true


Env:
RCLONE_VOLNAME=Pixeldrain
RCLONE_VERBOSE=1
RCLONE_LINKS=true
RCLONE_VFS_CACHE_MODE=full
RCLONE_VFS_CACHE_MAX_AGE=3d
RCLONE_CACHE_DIR=C:\Users\<user>\AppData\Local\rclone\PixeldrainService
RCLONE_BUFFER_SIZE=4M
RCLONE_VFS_READ_AHEAD=128M
RCLONE_VFS_DISK_SPACE_TOTAL_SIZE=2T
RCLONE_EXCLUDE_FROM=C:\Users\<user>\AppData\Local\rclone\PixeldrainService\exclude-file.txt

The command you were trying to run

rclone mount pixeldrainfs P:

A log from the command with the -vv flag

I couldn't reproduce it after setting RCLONE_VERBOSE=2. I will share it when it happens again.

Anything else?

The forum post I shared is not my own but I do believe this is the same issue.

Activity

  1. HarmfulBreeze commented on Sep 18, 2026

    @HarmfulBreeze
    Author

    Can't reproduce after trying out PR #9574 changes (rebased onto master).

  2. Kurptas commented on Sep 25, 2026

    @Kurptas

    Independent reproduction + root cause for the same failure, on Windows 11 + WinFsp 2.2.26215, rclone v1.75.1 and current master, over an SFTP remote (a name-preserving server: rclone serve sftp --local-encoding Raw), mount with --vfs-cache-mode full. The save action is exactly what your player does — write a temp file and rename it over the target — and, like you, I see the file end up truncated/empty while the temp file survives in the cache.

    The reason it needs a read first (i.e. "edit the file you just opened") is that the VFS keeps the cached file's descriptor open for clean items through the handle-caching grace period (vfs/vfscache/item.go), and Windows os.Rename (MoveFileEx) cannot replace a destination that is open — even when the handle was opened with FILE_SHARE_DELETE (verified with a ctypes experiment: os.replace fails with WinError 5 for both an open() handle and a CreateFileW(..., FILE_SHARE_DELETE) handle, and succeeds once closed). Hence File.Rename failed in Cache: ... Access is denied, and then:

    • vfs/file.go (File.rename) logged the failure at Info level and returned nil, so the FUSE layer saw success;
    • vfs/vfscache/item.go (item.rename) had already set item.name/item.o and re-targeted the pending write-back (writeback.Rename(id, newName)) before the file move, while Cache.rename returned before moving the map key — so the item claims a name whose cache file does not exist;
    • the write-back then resolves that name and uploads the destination's stale file (vfs/vfscache/item.go _store → fremote.NewObject/fcache.NewObject), which is the Copied (new) in your log; depending on which stale state wins you get a reverted file, a truncated one, or a 0-byte one (I got all three across timing variants).

    Timing variants I measured on the unpatched binary (same commands, only the delay between the read and the rename differed):

    sequence result
    read → write temp → rename over, immediately new content silently discarded, remote unchanged
    read → 2 s → write temp → rename over original truncated (21 B → 15 B)
    write temp → rename over (no read) works
    read → remount → write temp → rename over works (the remount recreates the item with no open fd)

    So the trigger is the open cache handle, not the remote backend.

    PR #9574 addresses this (error propagation in vfs/file.go + a Windows rename with FILE_RENAME_POSIX_SEMANTICS | FILE_RENAME_REPLACE_IF_EXISTS in lib/file). I built the same two changes locally and confirmed the end-to-end result: with them, the editor-style save succeeds and the file is correct (no Access is denied, no Copied (new)), on both v1.75.1 and master; with only the error propagation it fails loudly instead of losing data. Two things I found that #9574 does not cover, in case they matter for review: item.rename must move the cache files before mutating item.name/item.o (and must not re-target the write-back on failure), and File.rename should roll back the node's d/dPath/leaf when the rename fails; otherwise the item/node and their files stay inconsistent. I have those plus a reload fix (vfs/vfscache/cache.go walk() passes the OS-encoded path to Cache.get(), so a dirty item is dropped on remount) in #9975; the reload fix alone is #9974, and I linked both to this issue so they show up in its timeline.

    Note for anyone whose filenames contain non-ASCII punctuation: that is a separate defect from this one (a non-identity encoding on the remote makes a mount save land on a differently-quoted name). It is not part of the fix discussed here and I can file it separately if useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions