Library scan aborts, how can I find out where and why?

My music is on a NAS (homebrew Linux-based) which I access via SMB. So far I’ve been able to run a full scan of the media library. Today, after adding some material to the library, I noticed that the scan seems to abort after a relatively short time.

I noticed that OSMC’s account had no permission on some of the new files, so I added those (and made sure the account has permissions on all media files).

Still the library scan aborts in the process (when the progress bar is still close to the beginning).

I looked into the log in .kodi/temp/kodi.log but didn’t find anything that looked suspicious.

How can I find out what’s causing this?

Update: I installed the latest updates, rebooted and after that the scan went through smoothly, with some new files found. However, some are still missing, but nothing useful in kodi.log.

For anyone else having similar problems, here’s how to dig down deeper:

In System Settings, enable Event Logging, Notification Event Logging, Debug Logging and component-specific logging. Then, select the components you want to log: Since the suspect is SMB, select SMB and deselect everything else.

Now run another library scan, then examine the log file. On Linux, you will find it in /home/osmc/.kodi/temp/kodi.log.

This will show you exactly which files and folders OSMC tried to access. In my case it turned out it scanned everything, including the folder which held the files I’m still not seeing in my library.

The Event Log (viewable through the UI) shows “Failed to scan album” for a couple of folders.

Finally solved it—sort of…

I still don’t know why the albums failed to scan. I have rearranged a few things in my media library recently, and the items I changed somehow had the read permissions for OSMC’s account dropped—which explains why the scan didn’t find them initially. After noticing this, I fixed the permissions—that was still before the update and reboot.

The list of the albums that failed to scan appeared to match these items (though I can’t tell for sure if it was a 100% match).

Eventually I navigated into one of those folders from OSMC’s GUI, brought up the context menu and chose “Scan to library”. And lo and behold—not only that folder but also all the other missing ones suddenly showed up as recently added.

Still no idea what was going on under the hood here—my guess is that OSMC marked the files in question as “inaccessible” and skipped them on all subsequent scans; explicitly scanning one of these items to the library seems to have fixed that.