Getting lots of 'stale file handles'

hi! I don’t know if it is a problem that beets is causing or my something else on my system. Recently, I noticed a lot of stale file handle errors when importing with beets. I use Manjaro and import the files from a nfs share to a nfs share. I have noticed that during my automated imports the error doesn’t show up but that might be due to the -q parameter. In manual mode, however, I do see the error on a lot of folders.

Is this something that the nfs shares are causing or does beets have a specific timeframe in which a file has to be processed in?

The exact error message:

--- Logging error ---
Traceback (most recent call last):
    File "/usr/lib/python3.7/logging/", line 1038, in emit
    File "/usr/lib/python3.7/logging/", line 1018, in flush

OSError: [Errno 116] Stale file handle
Call stack:
    File "/usr/lib/python3.7/", line 885, in _bootstrap
    File "/usr/lib/python3.7/", line 917, in _bootstrap_inner
    File "/usr/lib/python3.7/site-packages/beets/util/", line 312, in run
out = self.coro.send(msg)
    File "/usr/lib/python3.7/site-packages/beets/util/", line 171, in coro
task = func(*(args + (task,)))
    File "/usr/lib/python3.7/site-packages/beets/", line 1375, in user_query
    File "/usr/lib/python3.7/site-packages/beets/", line 840, in choose_match
    File "/usr/lib/python3.7/site-packages/beets/", line 268, in log_choice
self.tag_log(u'asis', paths)
    File "/usr/lib/python3.7/site-packages/beets/", line 249, in tag_log'{0} {1}', status, displayable_path(paths))
    File "/usr/lib/python3.7/logging/", line 1383, in info
self._log(INFO, msg, args, **kwargs)
    File "/usr/lib/python3.7/site-packages/beets/", line 91, in _log

return super(StrFormatLogger, self)._log(level, m, (), exc_info, extra)
    Message: <beets.logging.StrFormatLogger._LogMessage object at 0x7f9b2ce46780>
    Arguments: ()

Weird. This seems to have to do with beets trying to send logging messages to stderr. That means it probably doesn’t have to do with the actual files that beets is working on or your NFS share.

When you invoke beets, are you doing anything funky with the redirection of its standard output streams?

not really, unless the -l option causes it?

this is the beet import:

beet import -i -l path/log.txt --set albumtype='album' ${src_dir}album/

No, that wouldn’t do it. We’re talking about the stderr stream, i.e., where beets tries to print its informational and warning messages and the like.

nope, their is no weird redirecting going on afaik. I have written a shell script that has a few import statements that are all similar to the one above with different folders. I don’t redirect any messages from that shell script other than the -l parameter in the import statements.

could it be that python might have a problem with running in the /bin/bash environment of the shell script?

It’s certainly worth a try! Can you try running some commands manually (outside of a script) and then inside the script to see if there’s a difference?

sorry for the delay! I have tried it without the shell script and also got the same error. I have noticed that it only occurs after a longer time of inactivity, like beets waiting for me for 20 minutes to make a decision on a match.

My theory is that the file handle to the log file which is on a NFS share becomes stale in that time, causing beets to spit out the error.

Could be! I wish I could offer more insight—it’s pretty hard to see what’s wrong, given the nondeterministic nature of the problem.

Maybe it would be worth trying without -l to validate your hypothesis?