Skip to content

service/tray: fix watcher missing items that exit during registration - #1191

Open
diogochaves wants to merge 1 commit into
quickshell-mirror:masterfrom
diogochaves:sni-watcher-register-race
Open

diogochaves wants to merge 1 commit into
quickshell-mirror:masterfrom
diogochaves:sni-watcher-register-race

Conversation

@diogochaves

Copy link
Copy Markdown

Fixes #1190

RegisterStatusNotifierItem and RegisterStatusNotifierHost checked that the service had an owner before watching it. A service that disconnected in between was never unregistered, because its NameOwnerChanged went out before the watch existed.

This watches the service first, then checks. If the owner is already gone, the watch is removed and the registration is ignored as before. This is the same order the SNI host, MPRIS and NetworkManager code already use when they look for a service.

If the service disconnects after the watch is added but before the check, the check ignores the registration and the pending event is then logged as Got service unregister event for untracked service. The warning is harmless here, and I can lower it to debug if you prefer.

Removing the watch in the ignored branch is safe even when another item from the same service is already registered. That item's watch was active before the service disconnected, so its unregister event is already pending, and removeWatchedService does not cancel pending events. I checked this by pausing quickshell with SIGSTOP, queueing a registration for a second item followed by the service's exit, and resuming: the first item was still removed.

Testing

In a nested Hyprland session with its own session bus, running the Omarchy bar on stock 0.3.1 and on this build:

  • The repro from the issue, in runs of 500: stock 0.3.1 leaked 1015 of 1500 registrations (411, 384 and 220 per run). This build leaked 0 of 1300.
  • The watcher connection's match rule count (GetConnectionStats) is the same before and after, so ignored registrations don't leave watches behind.
  • A long-lived service with two items: both register, and both are removed when it exits.
  • The SIGSTOP test above, repeated 11 times.

AI disclosure

I used an AI assistant (Claude) for this. It found the cause, wrote the change and ran the tests above, including the SIGSTOP test for the second-item case. I reviewed the change, reproduced the bug and the fix myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tray watcher keeps items that disconnect during registration

1 participant