Bug 444969

Summary: Digikam often freezes when dropping a tag over another to merge them
Product: [Applications] digikam Reporter: MarcP <iwannaberich>
Component: Tags-KeywordsAssignee: Digikam Developers <digikam-bugs-null>
Status: RESOLVED FIXED    
Severity: crash CC: caulier.gilles, iwannaberich, metzpinguin
Priority: NOR    
Version First Reported In: 7.4.0   
Target Milestone: ---   
Platform: Flatpak   
OS: Linux   
Latest Commit: Version Fixed/Implemented In: 7.4.0
Sentry Crash Report:
Attachments: console output when running digiKam-7.4.0-20210905T231405-x86-64-debug
console output when running digiKam-7.4.0-20211106T090435-x86-64-debug.appimage with bt

Description MarcP 2021-11-04 18:25:51 UTC
SUMMARY
I have found this problem in the latest 7.4 releases in flatpak (at least I have been having this problem regularly for the last few weeks). 

When I drag one keyword over another to merge them, sometimes digikam freezes completely, and you need to force close it. It also happens for faces in the People tab. Nothing responds, no menus or tabs. I don't think it happens all the time, but maybe 1/4 of the time. The progress bar shows that something started, but stays at 0%. It stays that way even if you leave it for hours. 

The problem is that changes are apparently written in the database, but they are never written into the metadata, so the pictures and the database are out of sync.

STEPS TO REPRODUCE
1. Go to the tag panel
2. Drag one tag on top of another. Select "Merge"

OBSERVED RESULT
Digikam often freezes completely

EXPECTED RESULT
The merge completes successfully and metadata is written.

SOFTWARE/OS VERSIONS

Linux/KDE Plasma: Digikam Build date: 3/11/21 10:27 (target: Debug)
Rev.: 4bc957fe855bfbbab639fd39159c64129cbd9571 on Ubuntu 20.04 LTS.
Comment 1 Maik Qualmann 2021-11-04 18:52:08 UTC
I can't think of any recent change that could lead to this. A log from the terminal when it freezes would be good.

Maik
Comment 2 MarcP 2021-11-04 19:19:45 UTC
I tried it now, tagged 6 pictures with a new tag, and then merging them, and digikam crashed. I ran it using flatpak run org.kde.digikam debug, but I don't see much output on the command line. Do you know how to enter debug mode in flatpak?
Comment 3 MarcP 2021-11-04 20:02:59 UTC
Created attachment 143215 [details]
console output when running digiKam-7.4.0-20210905T231405-x86-64-debug

I was able to capture the console output when running the latest appimage available, dating from 05/09/2021. I have attached the file. I'm not sure if it will help.
Comment 4 Maik Qualmann 2021-11-04 21:26:31 UTC
I cannot reproduce any problems with the current GIT version.
Exiv2 has many exceptions in your log that may lead to a crash.

Digikam::MetaEngine::Private::printExiv2ExceptionError: Cannot get metadata tag title with Exiv2:  (Error # 7 :  "Invalid tag name or ifdId `BurstSheed', ifdId 115"

Maik
Comment 5 Maik Qualmann 2021-11-04 21:41:25 UTC
From which camera are the images that lead to the crash? I found a thread at Exiv2 that "BurstSheed" is a typo and must be called "BurstSpeed". However, this is not relevant for the crash.

Maik
Comment 6 MarcP 2021-11-06 13:55:24 UTC
I am using the same 6 pictures for the tests. Two are scanned pictures, two are from an old phone (Motorola v525), two are from a Sony DSC-W7, and two from a smartphone (Nexus S). 

I have tried with the stable Digikam 7.3 appimage, and I can confirm that the problem does not happen in that version.
Comment 7 Maik Qualmann 2021-11-06 14:10:38 UTC
Can you please test it with today's AppImage?

Maik
Comment 8 MarcP 2021-11-06 15:30:59 UTC
I just tried (with digiKam-7.4.0-20211106T090435-x86-64-debug.appimage), and digikam still freezes when I try to merge two tags.
Comment 9 Maik Qualmann 2021-11-06 16:05:10 UTC
I have tested the current AppImage here and have merged tags several times, no problems. Tags are written into the images etc. Can you use the debug AppImage and start with the "debug" option, if digiKam freezes, in the terminal interrupt with CTRL+C, look with "bt" where digiKam is, continue with "c" and repeat this 3-4 times and post the log?

Maik
Comment 10 MarcP 2021-11-06 16:55:11 UTC
Created attachment 143286 [details]
console output when running digiKam-7.4.0-20211106T090435-x86-64-debug.appimage with bt

Here's the log including the backtrace. I hope you find something useful.
Comment 11 caulier.gilles 2021-11-06 17:32:57 UTC
Maik, 

It crash in Tags cache from database call, and QtCore.

In AppImage, Qt 5.15.2 and new libexiv2 0.27.5 are used. perhaps there is a conflict with a different libQt5 from the system, but, i already tested this case under CentOS where i enabled the modules Qt 5.5 | 5.7 | 5.12, and i never seen this dysfunction...  

Gilles
Comment 12 Maik Qualmann 2021-11-06 18:13:40 UTC
Yes, I've already seen it, the cause will be this external patch:

https://invent.kde.org/graphics/digikam/-/commit/91d6d899bf7663f1746bddfef9303d16ff9543e0

It is a race condition, probably compiler dependent / number of threads etc. We have a read / write lock problem here. I fix it, just have to recompile digiKam because openSUSE has updated a lot.

Maik
Comment 13 Maik Qualmann 2021-11-06 19:34:47 UTC
Git commit e1ab779c6a3f5594b656e3ee40955f528d7bdc9c by Maik Qualmann.
Committed on 06/11/2021 at 19:34.
Pushed by mqualmann into branch 'master'.

fix QReadWriteLock race condition in the TagsCache

M  +36   -29   core/libs/database/tags/tagscache.cpp

https://invent.kde.org/graphics/digikam/commit/e1ab779c6a3f5594b656e3ee40955f528d7bdc9c
Comment 14 Maik Qualmann 2021-11-07 16:44:55 UTC
Marc, can you reproduce the problem with the new AppImage? 

Maik
Comment 15 MarcP 2021-11-07 20:25:23 UTC
I just tried with today's appimage, and also with the latest flatpak, using the same pictures, and the problem seems to have been solved. Thanks!
Comment 16 Maik Qualmann 2021-11-07 20:29:24 UTC
Thank you for your feedback and for creating the backtraces to localize the problem. 

Maik