mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-05-30 23:40:40 +02:00
[Bug]: Scanner regularly breaks on network file transfer #866
Closed
opened 2026-04-24 23:24:36 +02:00 by adam
·
9 comments
No Branch/Tag Specified
master
book_tags_genres_dedupe
episode_download_fallback
Issue-4540-SortBy-StartedDate-and-FinishedDate
episode_meta_tagging
fix_authorize_race_condition
redirect_transcode_requests
progress_updated_sort
fix_ereader_socket_event
fix_change_empty_root_password
fix_podcast_session_track_index
fix_set_token
session_modal_user
localize_durations
fix_oidc_create_user
jwt_auth_refactor
fix_scanner_deleting_single_file_books
fix_mediaprogress_updatedat_2
experimental_next_client
podcast_episode_duration
episode-timestamps-clickable
book_author_secondary_sort_title
podcast_useragents
pathexists_user_access
fix_pathexists_join
book_author_secondary_sort
clean_duplicate_mediaprogress
sanitize_html_description
trix_prevent_attachments
check_path_api_fix
fix_mediaprogress_updatedat
increase_express_json_limit
fix_dockerfile_nunicode
search_episodes
audiobook_tools_update
episode_secondary_sorts
hls_stream_url_update
new_session_track_endpoint
audiobook_tools_enhancements
watcher_rescans_update
player_track_tooltip
fix_exclude_prefixes_crash
socket_item_events
fix_podcast_episode_scanner_promise
new_stats_controller
count_cache_for_userpermissions
parsing-opf-v3
validate_migration_files
fix-quick-match-all-crash
fix-chapter-end-sleep-timer
stringify_sequelize_query
remove-col-ambiguity
fix_next_prev_edit_description
details_trim_whitespace
fix_content_url_basepath
fix_logger_fatal
progress_bar_visibility
batch-edit-populate-map-details
feed_generator_updates
bookmark-modal-updates
migrate-library-item-in-scanner
migrate-new-library-items
migrate-podcasts-new-library-item-2
migrate-podcasts-new-library-item
fix-remove-episode-from-playlist
playback-session-use-new-library-item
refactor-library-item
fix-heatmap-caption
feed-episodes-upsert
share-media-player-media-session-api
remove-old-playlist
remove_old_collection_object
plugin-implementation-demo
feed_migration
refactor-feeds-from-item
fix_remove_authors_no_books
v2.17.3-fk-constraints-migration
migrations-first-upgrade
sqlite_2
feature/nuxt-target-server
waveform
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1
v1.3.4
v1.3.3
v1.3.1
v1.2.8
v1.2.6
v1.2.5
v1.2.4
v1.2.1
v1.1.15
v1.1.14
v1.1.13
v1.1.12
v1.1.11
v1.1.10
v1.1.9
v1.1.8
v1.0.0
0.9.61-beta.0
0.9.61-beta
Labels
Clear labels
authentication
backlog
bug
chapter editor
config-issue
ebooks
encoding/embedding
enhancement
help wanted
listening sessions & progress
planned
possible plugin
progress sync
pull-request
sorting/filtering/searching
unable to reproduce
upload
users & permissions
waiting
Mirrored from GitHub Pull Request
No Label
bug
Milestone
No items
No Milestone
Projects
Clear projects
No project
Assignees
adam (Adam Melkus)
Clear assignees
No Assignees
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: starred/audiobookshelf#866
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @lkiesow on GitHub (Jan 4, 2023).
Describe the issue
When I started using Audiobookshelf I've noticed that several of my imported books were not imported. Going through the logs, I found many errors related to imports which essentially boiled down to a failure to execute
ffprobesuccessfully.There are several other reports of something like this, like e.g. #1036, which suggest re-encoding the files to fix the metadata. But I found that just renaming the files would already fix the problem.
Later I also found that a lot of books which were successfully imported had an incorrect file size listed.
My suspicion was that the scanner would pick up and try to process files which had only been half-transferred to the server file system. Investigating the issue further, that seems to be true.
Steps to reproduce the issue
To see what happens, let's first generate an audio file. Not that this does not use the FFmpeg flag
faststart. This essentially means that metadata will be at the end of the file in this mp4 container:To verify that
ffprobefails when run on a half transferred file, we can just copy the first 100 MB to a new file and runffprobeon that file:This is exactly what I expected to happen.
Next, let's see how Audiobookshelf handles these this. I used
pvto simulate a slow network file transfer of 100 KB/s while copying the audio file to a library directory:Let this run for a few minutes, then hit
Ctrl + zto suspend this for a few minutes to simulate a slight network glich before resuming the process by running:The copy process continues, but Audiobookshelf starts processing the file. Since the metadata is still missing from the file,
ffprobewill fail and that means the import process will fail:Even if you update the file by copying the remaining data; either let the process finish or cancel it and run:
ABS will do nothing. The file will never be imported and the audiobook will be missing in the library, despite valid files being now available in the library directory.
But even if the metadata are already available, this leads to problems. As I mentioned above, I found that a lot of books have incorrect file sizes listed.
Let's generate a second file, this time using the
-movflags faststartparameter:Now running
ffprobeon the first part of the file will no longer fail:That's great, let's copy the file:
Again, wait a minute, hit
Ctrl + z, then resume usingfgif you like.ABS will pick up the file again, but this time it will be imported:
Unfortunately, the listed file size in the client is 6.15 MB while the actual file size is about 112 MB.
How to fix
The scanner should allow for a file to not be modified for a few seconds before trying to pick it up. This would likely already catch a number of the problematic imports.
However, this would likely only reduce the number of errors, not get rid of them. To completely fix the issue, ABS should keep a hash alongside the file name of imported file and re-import the file automatically if it is modified again.
Workaround
I used
scpfor my first batch but switched to usingrsynclater on. Fortunatelyrsynccopies files to a temporary file first which will not be picked up by ABS since it starts with a.and then move the file into place. This circumvents the problem. But using SMB, scp, FTP, … should all show this problem. Not for every file, but it will pop up eventually.Audiobookshelf version
2.x
@advplyr commented on GitHub (Jan 4, 2023):
Thanks for tracking this down and finding a way to reproduce. Abs is using Watcher to listen for new/removed files in the folders.
I'll have to dig into that lib again to see when it is sending the "add" event for a new file but I did a quick skim of the configurable options and it didn't look like there is one for this case.
The library can also emit events for changes to the file but I had that disabled because it was emitting events for every metadata change (which includes viewing the file) (see). If we choose to continue using this library we can enable that again and just build out a more robust check on what of the file is has changed.
There is an update on this library I've been meaning to check on and incorporate. The first step is probably to re-evaluate this library.
@lkiesow commented on GitHub (Jan 5, 2023):
I could see that event getting triggered if you run “Edit Book” → “Tools” → “Embed Metadata”, but why does ABS modify the file when you view (play?) the file?
@advplyr commented on GitHub (Jan 6, 2023):
Abs doesn't modify the file. I'm talking about the Watcher library can fire an event that the file changed just by viewing the file. This is because the file metadata stores the last time it was accessed.
I was just mentioning that as one reason why I disabled that event listener from Watcher. I hadn't built out a system of detecting what has changed on the file and I didn't want that firing every time the file is accessed.
@JohanPotgieter commented on GitHub (Oct 1, 2023):
I have the same issue as described in #2010. When uploading books via ABS it's not added to the library automatically. You have to scan the library to see the new addition.
@advplyr commented on GitHub (Oct 1, 2023):
@JohanPotgieter Currently the upload feature relies on the watcher to scan in the uploaded files. If you are using a network file system there is a good chance the watcher will not work for you.
@kymahi commented on GitHub (Oct 25, 2023):
@advplyr When you say "network file system" do you mean a network-connected storage drive accessed by the server? Because I'm seeing this issue on a USB-connected storage drive as well. This also is a newer issue, as I didn't have this issue until about June of this year after using this for about a year before that. Maybe an update to the Watcher library?
@advplyr commented on GitHub (Oct 25, 2023):
@kymahi Technically this is for any audio file that takes more than 4 seconds to copy. I just tested a possible solution by checking the file modified time and waiting for the modified time to stop changing before considering it as "added".
@advplyr commented on GitHub (Oct 25, 2023):
The solution I implemented is working for me. When new files are added the
mtimeof the file is checked every second until it stops changing.@advplyr commented on GitHub (Oct 29, 2023):
Fixed in v2.5.0