Persistent bad file descriptor when moving files to rclone Google Drive mount

What is the problem you are having with rclone?

As discussed in this thread, I am still seeing Bad file descriptor when trying to upload data through an rclone mount to Google Drive. However, for newer versions of Sonarr, once the Bad file descriptor issue occurs for one upload, then it then is seems to occur for every future upload, meaning that I am unable to upgrade Sonarr. The following is an example Sonarr log snippet:

[Warn] ImportApprovedEpisodes: Couldn't import episode /mnt/[REDACTED]/[REDACTED]/series/S.W.A.T.2017.S06E10.1080p.WEB.h264-KOGi.mkv

[v10.0.0.29460] System.UnauthorizedAccessException: Access to the path is denied.
 ---> System.IO.IOException: Bad file descriptor
   --- End of inner exception stack trace ---
   at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirectory, Func`2 errorRewriter)
   at System.IO.FileSystem.CopyFile(String sourceFullPath, String destFullPath, Boolean overwrite)
   at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite)
   at NzbDrone.Mono.Disk.DiskProvider.TransferFilePatched(String source, String destination, Boolean overwrite, Boolean move) in /workspace/src/NzbDrone.Mono/Disk/DiskProvider.cs:line 328

As suggested in the reply the thread linked above, I tried --vfs-cache-mode writes which works as expected, however similarly to this thread, this setting does not work very well with Sonarr as it believes that it has finished uploading a file when in fact it is still cached locally; due to the way I am running Sonarr (in a container on Kubernetes) if Sonarr dies or is restarted I lose the rclone mount and cache leaving missing or half-finished uploads since Sonarr believes the upload has already finished successfully.

For this reason, I am hoping that this issue can be fixed without using --vfs-cache-mode writes. As I understand it, some applications simply do not work without this option so Sonarr may be one of them, but since a number of uploads sometimes work when Sonarr first starts (before they then start failing continuously) I am hoping that there is something that can be changed within rclone to fix or improve this behaviour.

Run the command 'rclone version' and share the full output of the command.

rclone v1.59.2
- os/version: alpine 3.16.2 (64 bit)
- os/kernel: 5.4.92-flatcar (x86_64)
- os/type: linux
- os/arch: amd64
- go/version: go1.18.6
- go/linking: static
- go/tags: none

I have also tried using rclone v1.61.1 with the same result.

Which cloud storage system are you using? (eg Google Drive)

Google Drive

The command you were trying to run (eg rclone copy /tmp remote:tmp)

rclone mount "media:TV Shows" /mnt \
    --daemon \
    --config=/tmp/rclone.conf574021724 \
    --allow-non-empty=true \
    --cache-info-age=6h0m0s \
    --dir-cache-time=8760h \
    --drive-chunk-size=256M \
    --bwlimit=512K:5M \
    --log-file=/tmp/sonarr.log.txt \
    --attr-timeout=1m \
    --drive-acknowledge-abuse=true \
    --use-mmap=true \
    --log-level=DEBUG \
    --allow-other=true \
    --buffer-size=64M \
    --tpslimit-burst=10 \
    --uid=1000 \
    --tpslimit=10 \
    --vfs-cache-mode=off \
    --debug-fuse=true \
    --cache-chunk-clean-interval=1m0s \

The rclone config contents with secrets removed.

type = drive
client_id = [REDACTED]
client_secret = [REDACTED]
scope = drive
token = [REDACTED]
root_folder_id = [REDACTED]

type = crypt
remote = gdrive:Media
password = [REDACTED]
password2 = [REDACTED]

A log from the command with the -vv flag

You can find the relevant error by searching for Bad file descriptor:

I fixed this by patching Sonarr to shell out to cp instead: Sonarr/DiskProvider.cs at 9441fcdaf9258f7681534f8d76a1bf415cb32639 · dippynark/Sonarr · GitHub

It looks like the Sonarr issue was with the underlying C# system library: File.Copy Method (System.IO) | Microsoft Learn

This topic can be closed as rclone is working as expected

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.