Akonadi: fix racy code in (MimeType|Resource)::retrieveByNameOrCreate
ClosedPublic

Authored by dfaure on Feb 9 2019, 9:58 PM.

Details

Summary

If two threads (TA and TB) would call retrieveByNameOrCreate() with a
*different* argument (say A and B), TA might acquire the lock to create A,
and meanwhile TB will fail the tryLock() and never create B.

Solution: lock around lookup+creation, don't use tryLock, simplify code by using QMutexLocker.

I found this by reading the code, but indirectly this seems to also
fix akonadiserver locking up in mysql queries during akonaditest
startup (sometimes), probably because it reduces concurrent querying a bit...

Test Plan

ctest, the "Resource synchronization timed out for akonadi_knut_resource_0"
errors (that happened approx 30% of the time) are gone.

Diff Detail

Branch
Applications/18.12
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 8090
Build 8108: arc lint + arc unit
dfaure requested review of this revision.Feb 9 2019, 9:58 PM
dfaure created this revision.
dfaure edited the summary of this revision. (Show Details)Feb 10 2019, 9:27 AM
dfaure set the repository for this revision to R165 Akonadi .
Restricted Application added a project: KDE PIM. · View Herald TranscriptFeb 10 2019, 9:27 AM
dvratil accepted this revision.Feb 10 2019, 11:14 PM

I believe the attempt here was to make the most common case of successful retrieval lock-free, but I now realize how broken that approach was. Thanks for the patch!

This revision is now accepted and ready to land.Feb 10 2019, 11:14 PM
dfaure closed this revision.Feb 11 2019, 8:00 AM