vfs: fix backends being Shutdown too early when startup takes a long time

Before this change if the VFS took more than 5 to initialise (which
can happen if there is a lot of files or a lot of files which need
uploading) the backend was dropped out of the cache before the VFS was
fully created.

This was noticeable in the dropbox backend where the batcher Shutdown
too soon and prevented further uploads.

This fixes the problem by Pinning backends before the VFS cache is
created.

https://forum.rclone.org/t/if-more-than-251-elements-in-the-que-to-upload-fails-with-batcher-is-shutting-down/38076/2
This commit is contained in:
Nick Craig-Wood 2023-05-14 11:46:06 +01:00
parent 3115ede1d8
commit fc798d800c
1 changed files with 3 additions and 2 deletions

View File

@ -227,13 +227,14 @@ func New(f fs.Fs, opt *vfscommon.Options) *VFS {
fs.Logf(f, "--vfs-cache-mode writes or full is recommended for this remote as it can't stream")
}
vfs.SetCacheMode(vfs.Opt.CacheMode)
// Pin the Fs into the cache so that when we use cache.NewFs
// with the same remote string we get this one. The Pin is
// removed when the vfs is finalized
cache.PinUntilFinalized(f, vfs)
// This can take some time so do it after the Pin
vfs.SetCacheMode(vfs.Opt.CacheMode)
return vfs
}