Sonarr Unable to Delete files Off Disk

Sonarr version (exact version): 4.0.4.1668
Mono version (if Sonarr is not running on Windows): N/A - Docker - Package Version
4.0.4.1668-ls59 by linuxserver.io
OS: Ubuntu server - Docker
Debug logs: Ubuntu Pastebin
Description of issue: I’m not sure when exactly this happened, but I noted today that when I was deleting older TV shows, the video files on disk are not being deleted. It looks like Sonarr is deleting the emby metadata files for the show (like poster, nfo file, fanart, etc.), but the season folders are left basically untouched, and then sonarr throws an error that the directory is not empty.

I know that sonarr in docker has access to modify the contents of the folder that my shows are stored in since I’m able to upgrade episode files without issue.

I currently have Ubuntu server running in a VM on proxmox that has sonarr running in docker. The TV show folder is hosted on my windows server and is mounted into my ubuntu machine, and then mapped into the docker container.

I’ve had this setup working for years, so I don’t think there is a permissions issue (and sonarr is also able to freely rename/delete/write files to this folder as well without error), but I’m definitely not an expert.

Please let me know what else I can provide.

Thanks

I just updated to the following and the issue persists:

Version 4.0.4.1695
Package Version 4.0.4.1695-ls61 by 
.NET Yes (6.0.13)
Docker Yes
Database Sqlite 3.44.2
Database Migration 205
AppData Directory /config
Startup Directory /app/sonarr/bin
Mode Console

Here is another debug log in case it helps. This time I tried to delete the show ‘Debunked’:

https://paste.ubuntu.com/p/zY2FdNdrfD/

Is this folder open in Windows Explorer or something has a lock on it? Sonarr deletes the folder recursively so it should only fail with this error if that deletion of all the files fails for some reason.

Nope, I confirmed that the folder is not open in Windows explorer, and there shouldn’t be anything else that’s locking the files.

Right after Sonarr fails at deleting the files, I’m able to navigate to the same folder within the container and delete the file manually using rm -rfd

Are any files removed or it fails immediately?
Are there any hidden/protected files in that folder structure that’s being deleted?

Not sure how this could happen and so far haven’t been able to reproduce.

Thanks for looking into this for me.

Sonarr is able to remove the metadata and poster/fanart files in the root of the series folder, but it doesn’t remove the season folders, nor the files within the season folders.

Are you actually sure about this? What are the permissions on folders/files sonarr can/can’t delete?

So I was only partially right before. All of the metadata files in the show folder are deleted and actually SOME of the video and metadata files are deleted in the Season folders (I originally thought none were). If I add the now unmapped show back into Sonarr and delete again, more files in the Season folders are deleted.

If I do this between 2 - 4 times, all of the files in the Show folder are eventually deleted, and then the main show folder is then deleted.

I just tested this on probably 5 or 6 different shows, and all worked the exact same way.

Here is what the folder permissions show for my main TV show folder (mounted via CIFS into my Ubuntu Server from my Windows 10 server) and an example show and season folder

kevin@server-ubuntu:/media/v/TV$ ls -ld
drwxr-xr-x 2 kevin root 65536 Jun  1 22:28 .
kevin@server-ubuntu:/media/v/TV$ cd The\ Essex\ Serpent/
kevin@server-ubuntu:/media/v/TV/The Essex Serpent$ ls -l
total 9788
-rwxr-xr-x 1 kevin root  181983 May 19  2022  banner.jpg
-rwxr-xr-x 1 kevin root  315041 Jul  1  2022  clearart.png
-rwxr-xr-x 1 kevin root   32203 May 19  2022  clearlogo.svg
-rwxr-xr-x 1 kevin root 2244316 May 19  2022  fanart1.jpg
-rwxr-xr-x 1 kevin root  619711 May 19  2022  fanart2.jpg
-rwxr-xr-x 1 kevin root  309883 May 19  2022  fanart3.jpg
-rwxr-xr-x 1 kevin root  954856 May 19  2022  fanart4.jpg
-rwxr-xr-x 1 kevin root 1630223 May 19  2022  fanart.jpg
-rwxr-xr-x 1 kevin root  504942 May 19  2022  landscape.jpg
-rwxr-xr-x 1 kevin root 1111820 May 19  2022  poster.jpg
drwxr-xr-x 2 kevin root       0 Dec  7 23:03 'Season 01'
-rwxr-xr-x 1 kevin root  249941 Jul  1  2022  season01-banner.jpg
-rwxr-xr-x 1 kevin root  724058 Jul  1  2022  season01-landscape.jpg
-rwxr-xr-x 1 kevin root 1111820 May 19  2022  season01-poster.jpg
-rwxr-xr-x 1 kevin root    2772 May 14 11:01  tvshow.nfo
kevin@server-ubuntu:/media/v/TV/The Essex Serpent$ cd Season\ 01/
kevin@server-ubuntu:/media/v/TV/The Essex Serpent/Season 01$ ls -l
total 23088348
-rwxr-xr-x 1 kevin root        449 May 14 11:01  season.nfo
-rwxr-xr-x 1 kevin root 4066622081 Nov  7  2023 'The Essex Serpent S01E01 [WEBDL-1080p][EAC3 Atmos 5.1][h264]-NTb.mkv'
-rwxr-xr-x 1 kevin root      16048 May  7 09:55 'The Essex Serpent S01E01 [WEBDL-1080p][EAC3 Atmos 5.1][h264]-NTb.nfo'
-rwxr-xr-x 1 kevin root    1818222 Nov  7  2023 'The Essex Serpent S01E01 [WEBDL-1080p][EAC3 Atmos 5.1][h264]-NTb-thumb.jpg'
-rwxr-xr-x 1 kevin root 4091961644 Nov  7  2023 'The Essex Serpent S01E02 [WEBDL-1080p][EAC3 Atmos 5.1][h264]-NTb.mkv'
-rwxr-xr-x 1 kevin root      16657 May  7 09:55 'The Essex Serpent S01E02 [WEBDL-1080p][EAC3 Atmos 5.1][h264]-NTb.nfo'
-rwxr-xr-x 1 kevin root     941298 Nov  7  2023 'The Essex Serpent S01E02 [WEBDL-1080p][EAC3 Atmos 5.1][h264]-NTb-thumb.jpg'
-rwxr-xr-x 1 kevin root 3432219118 Nov  7  2023 'The Essex Serpent S01E03 [WEBDL-1080p][EAC3 Atmos 5.1][h264]-NTb.mkv'
-rwxr-xr-x 1 kevin root      15059 May  7 09:55 'The Essex Serpent S01E03 [WEBDL-1080p][EAC3 Atmos 5.1][h264]-NTb.nfo'
-rwxr-xr-x 1 kevin root     452127 Nov  7  2023 'The Essex Serpent S01E03 [WEBDL-1080p][EAC3 Atmos 5.1][h264]-NTb-thumb.jpg'
-rwxr-xr-x 1 kevin root 4037767461 Nov  7  2023 'The Essex Serpent S01E04 [WEBDL-1080p][EAC3 Atmos 5.1][h264]-NTb.mkv'
-rwxr-xr-x 1 kevin root      15421 May  7 09:55 'The Essex Serpent S01E04 [WEBDL-1080p][EAC3 Atmos 5.1][h264]-NTb.nfo'
-rwxr-xr-x 1 kevin root     727228 Nov  7  2023 'The Essex Serpent S01E04 [WEBDL-1080p][EAC3 Atmos 5.1][h264]-NTb-thumb.jpg'
-rwxr-xr-x 1 kevin root 3871834501 Nov  7  2023 'The Essex Serpent S01E05 [WEBDL-1080p][EAC3 Atmos 5.1][h264]-NTb.mkv'
-rwxr-xr-x 1 kevin root      15220 May  7 09:55 'The Essex Serpent S01E05 [WEBDL-1080p][EAC3 Atmos 5.1][h264]-NTb.nfo'
-rwxr-xr-x 1 kevin root     355242 Nov  7  2023 'The Essex Serpent S01E05 [WEBDL-1080p][EAC3 Atmos 5.1][h264]-NTb-thumb.jpg'
-rwxr-xr-x 1 kevin root 4136805586 Nov  7  2023 'The Essex Serpent S01E06 [WEBDL-1080p][EAC3 Atmos 5.1][h264]-NTb.mkv'
-rwxr-xr-x 1 kevin root      15898 May  7 09:55 'The Essex Serpent S01E06 [WEBDL-1080p][EAC3 Atmos 5.1][h264]-NTb.nfo'
-rwxr-xr-x 1 kevin root     804033 Nov  7  2023 'The Essex Serpent S01E06 [WEBDL-1080p][EAC3 Atmos 5.1][h264]-NTb-thumb.jpg'

any other thoughts/ideas?

It seems like the delete thinks it’s successful then tries to delete the folder and fails, but it’s happening within the .net framework so it’s not something we can directly control.

I don’t know how this recursive delete works internally, but I wonder if the directory listing isn’t returning all files then the delete only deletes what it knows about.

If instead of trying to delete you open manage episodes or rescan the series then delete does that change anything?

Beyond that, I don’t have any ideas outside of something with the SMB configuration as we’ve seen issues with SMB in some setups, but that has mostly lead to Sonarr being unable to add a root folder because the file that is created isn’t present immediately and Sonarr fails to delete it and treats it as a write failure.

Thanks - so I tried to rescan a series and then delete, but the same thing happened. I then took a different series and then went into manage episodes and deleted all of the episode files, which worked deleting all of the episodes on disk. Then I deleted the series, and the top level series folder was also deleted.

I tried this with a few more shows (both with single seasons and multiple seasons), and it worked.

It seems that for some reason the main delete command is not recursuvely deleting the episode files, causing the final delete to fail.

Could the issue be related to my disk performance? My shows are on a drivepool on my windows server, and sometimes the performance of the disks can be on the slower side. I’ve had this setup this way since before I started using sonarr, but the performance of the drives could be slowing down, causing slower read/write/deletes over smb?