Library scan progress races can flip a library to idle mid-scan #60
Loading…
Reference in a new issue
No description provided.
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?
Found in Nye's audit of
dae07b9on main.process_worker.ex:205only skips whenscan_progress_stage == "scanning", but that's first written atscan_worker.ex:254-257, afterdiscover_filesand the first file.mark_scanning(libraries.ex:181) only setsscanning_status, so a ProcessWorker canmark_scan_completewhile the scan is queued or walking a big share, andstart_scanthen allows a second scan.Fix: set
scan_progress_stage"scanning" (current 0, total nil) inmark_scanningor at the top ofScanWorker.perform, with a test.write_library_progress(process_worker.ex:217-243) counts, then writes with no lock, so a stale "processing 9/10" can land after complete and leave a stuck bar.Fix: a transaction with
pg_advisory_xact_lock(key, library_id), like@book_match_lock, and only show the bar (admin_libraries_live.html.heex:44) whilescanning_status == "scanning".scan_worker.ex:74ignores theupdate_scan_progressresult. Match{:ok, _}, and on errorLogger.errorwith library_id and changeset errors, then fall back tomark_scan_complete/clear_scan_progress.process_worker.ex:177-178: when the finalupdate_ebookfails, it callshandle_errorbut notupdate_library_progress. Call it too.scan_worker_test.exs:242only passes because Oban testing is:manual).