[SNI] Fix race condition in item registration

Authored by kmaterka on Mon, Feb 3, 1:09 PM.



If StatusNotifierItem is registered and then immediately destroyed, it is possible that QDBusServiceWatcher will not emit the serviceUnregistered signal.
Add an additional check to avoid such situations.

BUG: 416652
FIXED-IN: 5.18.0

Test Plan

Telegram should not add empty items.

Diff Detail

R120 Plasma Workspace
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.
kmaterka requested review of this revision.Mon, Feb 3, 1:09 PM
kmaterka created this revision.

It is hard to reproduce, but with enough tries you should get empty items in "hidden" area of system tray. I used this script:

for i in `seq 1 100`; do
        echo $i
        telegram-desktop &
        sleep 2
        killall telegram-desktop

Well identified, it is racey.

But the solution seems off

on line 68 we check
on line 75 we implicitly check again
now we're checking a 3rd time!

I think we can instead solve it with some re-arranging

 if (QDBusConnection::sessionBus().interface()->isServiceRegistered(service).value())  {
  // as before except for the moved line
} else {
kmaterka updated this revision to Diff 74929.Mon, Feb 3, 3:48 PM

Updated the code. This time I was not event able to reproduce race condition. Is something like this OK?

kmaterka added inline comments.Mon, Feb 3, 3:49 PM

Is this OK? Are mid-method returns allowed?

davidedmundson accepted this revision.Mon, Feb 3, 3:53 PM
davidedmundson added inline comments.

They are

This revision is now accepted and ready to land.Mon, Feb 3, 3:53 PM
This revision was automatically updated to reflect the committed changes.