Bug 475529 - Possible database corruption by running rescans in parallel
Summary: Possible database corruption by running rescans in parallel
Status: RESOLVED FIXED
Alias: None
Product: kphotoalbum
Classification: Applications
Component: Backend (show other bugs)
Version: 5.11.0
Platform: Ubuntu Linux
: NOR crash
Target Milestone: ---
Assignee: KPhotoAlbum Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-10-12 18:40 UTC by Pierre Etchemaïté
Modified: 2023-10-12 21:46 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Pierre Etchemaïté 2023-10-12 18:40:48 UTC
SUMMARY
Starting a rescan while another rescan is in progress can lead to duplicate entries being added to the database.
Upon database reload, KPhotoAlbum may detect the inconsistency and exit.

STEPS TO REPRODUCE
1. Create new image(s)
2. Start a disk rescan
3. Start a disk rescan again while previous one is still in progress

OBSERVED RESULT
Duplicate images in the database. If database is saved, upon reloading KPhotoAlbum may detect the issue and exit:

    ~ ᐅ kphotoalbum 
    kphotoalbum.DB: Merging duplicate entry for file "jean-pierre/Post mortem/Inventaire/I10/I10,1/200105 b.tif"
    ~ ᐅ

EXPECTED RESULT
Either queue the rescan, or inform the user that a rescan is ongoing and ask whether it should be cancelled and rescan started over.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Ubuntu 22.04.3 (only using KDE libs)
KDE Plasma Version:  5.24.7
KDE Frameworks Version: 5.92.0 
Qt Version: 5.15.3

ADDITIONAL INFORMATION
I'm scanning a NAS shared folder, so rescanning can take a few minutes and there's no visual clue that a rescan is still in progress. So it genuinely happened a few times.
I've seen reloading fix the duplicates once, maybe image checksums helped?
Comment 1 Johannes Zarl-Zierl 2023-10-12 20:45:39 UTC
Starting a rescan while the rescan is still running in the background actually crashed on me, so I'm treating this as "bug confirmed". Thanks for reporting this!
Comment 2 Johannes Zarl-Zierl 2023-10-12 21:46:45 UTC
Git commit 5667e29083004009cf60510c62ea690f1d234bc3 by Johannes Zarl-Zierl.
Committed on 12/10/2023 at 23:42.
Pushed by johanneszarl into branch 'master'.

Prevent scanning for new images in parallel

Add a mutex to prevent the user from starting a scan for new images
while another scan is still running.
This fixes a failed assertion if assertions are enabled, and potential
database corruption if assertions are not enabled.

M  +1    -0    CHANGELOG.md
M  +24   -3    DB/NewImageFinder.cpp
M  +13   -4    DB/NewImageFinder.h

https://invent.kde.org/graphics/kphotoalbum/-/commit/5667e29083004009cf60510c62ea690f1d234bc3