[contacts/ContactModifyJob] Avoid race condition

Authored by poboiko on Mar 21 2020, 11:15 AM.

Description

[contacts/ContactModifyJob] Avoid race condition

Summary:
This patch is similar to D28178: [contacts] Fix ContactCreateJob with a photo. Although uid is populated, and we can
freely dispatch both contact and photo modify requests in parallel, the
following race condition still sometimes happens:

  1. Contact modify request dispatched
  2. Contact photo modify request dispatched
  3. Photo reply arrives

At this point, d->lastContact is not yet populated, and we call
processNextContact(), which repeats steps 1 and 2 for the very same contact.
Which could happen again and again, if photo reply arrives first again.

Instead, I suggest to fire photo modify request only after we receive reply
for contact modify request, ensuring everything happens in the following order:

  1. Contact modify request dispatched
  2. Contact modify reply received
  3. Contact photo modify request dispatched
  4. Contact photo reply received

Test Plan:

  1. Modify a contact via KAddressBook
  2. Check logs
  3. (without patch) Bunch of modify requests somtimes gets fired
  4. (with patch) Only one modify request gets fired

Reviewers: dvratil

Reviewed By: dvratil

Subscribers: kde-pim

Tags: KDE PIM

Differential Revision: https://phabricator.kde.org/D28181

Details

Committed
poboikoMar 21 2020, 4:16 PM
Reviewer
dvratil
Differential Revision
D28181: [contacts/ContactModifyJob] Avoid race condition
Parents
R477:7de9af3d297a: [contacts] Fix ContactCreateJob with a photo
Branches
Unknown
Tags
Unknown