Race condition when adding new books to library #189

Closed
opened 2026-04-24 23:00:39 +02:00 by adam · 3 comments
Owner

Originally created by @wtanksleyjr on GitHub (Jan 28, 2022).

This is a situation I find myself in all the time: I add a folder, copy an OPF in, and then put the MP3s in. But when I look at the book in Audiobookshelf, I find that it's only loaded the title, since it did that as soon as it saw the folder and before I put any files in it.

There are two interesting "race conditions" here: first, it's loading books even when there's nothing to load. Second, once it triggers the load, it doesn't reload when new files are added, even when the OPF should override the folder metadata. Worse, this decision cannot apparently be fixed: clicking reload metadata only looks at the folder, ignoring the OPF. The only way around that is to move the folder (so the system thinks it's a new book) and delete the old book (since it's now invalid).

Originally created by @wtanksleyjr on GitHub (Jan 28, 2022). This is a situation I find myself in all the time: I add a folder, copy an OPF in, and then put the MP3s in. But when I look at the book in Audiobookshelf, I find that it's only loaded the title, since it did that as soon as it saw the folder and before I put any files in it. There are two interesting "race conditions" here: first, it's loading books even when there's nothing to load. Second, once it triggers the load, it doesn't reload when new files are added, even when the OPF should override the folder metadata. Worse, this decision cannot apparently be fixed: clicking reload metadata only looks at the folder, ignoring the OPF. The only way around that is to move the folder (so the system thinks it's a new book) and delete the old book (since it's now invalid).
adam closed this issue 2026-04-24 23:00:39 +02:00
Author
Owner

@advplyr commented on GitHub (Jan 28, 2022):

Pressing re-scan on the individual audiobook modal OR pressing the force re-scan for the library should both be parsing the OPF file again. There could be a bug there I will test out.

The watcher can be improved. Right now once it detects an update in the library it adds it to an array and waits 4 seconds until no more updates are made. For a new audiobook it should only create the audiobook in abs if there is an audio file or ebook file inside the folder, so just creating the folder won't add the audiobook.

Can you confirm that all the files are showing up in audiobookshelf? Can you give me more specific steps to reproduce the issue?

@advplyr commented on GitHub (Jan 28, 2022): Pressing re-scan on the individual audiobook modal OR pressing the force re-scan for the library should both be parsing the OPF file again. There could be a bug there I will test out. The watcher can be improved. Right now once it detects an update in the library it adds it to an array and waits 4 seconds until no more updates are made. For a new audiobook it should only create the audiobook in abs if there is an audio file or ebook file inside the folder, so just creating the folder won't add the audiobook. Can you confirm that all the files are showing up in audiobookshelf? Can you give me more specific steps to reproduce the issue?
Author
Owner

@wtanksleyjr commented on GitHub (Jan 28, 2022):

Oof! Well, I'm going to have to do some more work... I'd already cleaned up
the mess from before. It involved (first) many books that seemed to be
loaded in the middle of copying MP3s into them, which were marked as
broken; many "missing" books that were actually just husks of a book that
I'd moved somewhere else (because I changed my naming conventions to be
more audiobookshelf-friendly).

There's one I can report on right now, although not with as much detail as
I'd like.

I'd loaded a book and had gotten an error (the files were all there but
it'd flagged it for some reason, I don't remember right now but it was my
fault), so I fixed the error and put its OPF file in. Once I did that, I
clicked "rescan" while on that book's webpage. The book didn't change
except to change from its old error message to "Missing" (and all of the
files vanished from the bottom half of the screen). I searched for the
title, and found both the same "Missing" book and a new book with all the
correct files and correct metadata. It seems that the "bad" book wasn't
updated with new information; instead a new book was created and populated,
and the old bad book was left in place.

Oh, I remember one more problem that might actually be reproducible. Some
of my "books" are actually podcasts, and for some reason podcasts are
HORRIBLE about providing metadata, episode numbers almost never appear
anywhere including the titles. I rename the episodes with sortable episode
numbers as much as I can. I actually like how you flag books when I miss
one or two episodes. Anyhow, when I see you flag one of those, I go into
the command line and rename the bad episodes; I then go back to the book's
page and click "reload metadata." Ooops! This always fails; what actually
happens is that audiobookshelf keeps its record of the old filenames, but
marks them as "missing"; it then adds all of the new filenames as "other
files" (i.e. not as part of the audiobook!). The only solution is to delete
the book and completely reload it, and honestly I haven't found a way to do
that without nuking everything and starting over.

On Fri, Jan 28, 2022 at 6:49 AM advplyr @.***> wrote:

Pressing re-scan on the individual audiobook modal OR pressing the re-scan
metadata for the library should both be parsing the OPF file again. There
could be a bug there I will test out.

The watcher can be improved. Right now once it detects an update in the
library it adds it to an array and waits 4 seconds until no more updates
are made. For a new audiobook it should only create the audiobook in abs if
there is an audio file or ebook file inside the folder, so just creating
the folder won't add the audiobook.

Can you confirm that all the files are showing up in audiobookshelf? Can
you give me more specific steps to reproduce the issue?


Reply to this email directly, view it on GitHub
https://github.com/advplyr/audiobookshelf/issues/335#issuecomment-1024293855,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAJ7H6LP75UBA4JAUWLWCDTUYKUGBANCNFSM5M7KWGDA
.
Triage notifications on the go with GitHub Mobile for iOS
https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675
or Android
https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID:
@.***>

@wtanksleyjr commented on GitHub (Jan 28, 2022): Oof! Well, I'm going to have to do some more work... I'd already cleaned up the mess from before. It involved (first) many books that seemed to be loaded in the middle of copying MP3s into them, which were marked as broken; many "missing" books that were actually just husks of a book that I'd moved somewhere else (because I changed my naming conventions to be more audiobookshelf-friendly). There's one I can report on right now, although not with as much detail as I'd like. I'd loaded a book and had gotten an error (the files were all there but it'd flagged it for some reason, I don't remember right now but it was my fault), so I fixed the error and put its OPF file in. Once I did that, I clicked "rescan" while on that book's webpage. The book didn't change except to change from its old error message to "Missing" (and all of the files vanished from the bottom half of the screen). I searched for the title, and found both the same "Missing" book and a new book with all the correct files and correct metadata. It seems that the "bad" book wasn't updated with new information; instead a new book was created and populated, and the old bad book was left in place. Oh, I remember one more problem that might actually be reproducible. Some of my "books" are actually podcasts, and for some reason podcasts are HORRIBLE about providing metadata, episode numbers almost never appear anywhere including the titles. I rename the episodes with sortable episode numbers as much as I can. I actually like how you flag books when I miss one or two episodes. Anyhow, when I see you flag one of those, I go into the command line and rename the bad episodes; I then go back to the book's page and click "reload metadata." Ooops! This always fails; what actually happens is that audiobookshelf _keeps_ its record of the old filenames, but marks them as "missing"; it then adds all of the new filenames as "other files" (i.e. not as part of the audiobook!). The only solution is to delete the book and completely reload it, and honestly I haven't found a way to do that without nuking everything and starting over. On Fri, Jan 28, 2022 at 6:49 AM advplyr ***@***.***> wrote: > Pressing re-scan on the individual audiobook modal OR pressing the re-scan > metadata for the library should both be parsing the OPF file again. There > could be a bug there I will test out. > > The watcher can be improved. Right now once it detects an update in the > library it adds it to an array and waits 4 seconds until no more updates > are made. For a new audiobook it should only create the audiobook in abs if > there is an audio file or ebook file inside the folder, so just creating > the folder won't add the audiobook. > > Can you confirm that all the files are showing up in audiobookshelf? Can > you give me more specific steps to reproduce the issue? > > — > Reply to this email directly, view it on GitHub > <https://github.com/advplyr/audiobookshelf/issues/335#issuecomment-1024293855>, > or unsubscribe > <https://github.com/notifications/unsubscribe-auth/AAJ7H6LP75UBA4JAUWLWCDTUYKUGBANCNFSM5M7KWGDA> > . > Triage notifications on the go with GitHub Mobile for iOS > <https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675> > or Android > <https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>. > > You are receiving this because you authored the thread.Message ID: > ***@***.***> >
Author
Owner

@advplyr commented on GitHub (Jan 29, 2022):

Abs stores the inode value for each file so that it doesn't add the same file or audiobook folder twice. It sounds like that inode value is changing which is causing the duplicates.
Can you share your setup? What OS you are on, abs server version, if you are using a remote file system, symlinks, etc.

@advplyr commented on GitHub (Jan 29, 2022): Abs stores the inode value for each file so that it doesn't add the same file or audiobook folder twice. It sounds like that inode value is changing which is causing the duplicates. Can you share your setup? What OS you are on, abs server version, if you are using a remote file system, symlinks, etc.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/audiobookshelf#189