mirror of
https://github.com/rmcrackan/Libation.git
synced 2026-09-12 21:57:19 -04:00
Configuration.Instance is a process-wide singleton read and written from the UI thread, BackgroundWorker callbacks and download workers at the same time, but PersistentDictionary guarded only its file writes. Its two Dictionary caches were touched without synchronization, so concurrent inserts eventually corrupted them and threw "Operations that change non-concurrent collections must have exclusive access" (issue #1959, reported from MainVM.UpdateCountsBw_Completed reading AutoDownloadEpisodes while a second GetCounts pass ran). Reads on the file were unguarded too: Exists/GetJObject could observe a partially written Settings.json, and readFile responds to empty contents by rewriting the file, so a reader racing a writer could scramble the settings on disk. Take one lock across each operation's cache and file access, and keep logging outside it by having writeFile report whether it rewrote the file. Co-authored-by: rmcrackan <rmcrackan@gmail.com>