fix(inhibitor): use a private system bus connection and reconnect when closed - #5272
Open
ravi-arnan wants to merge 1 commit into
Open
fix(inhibitor): use a private system bus connection and reconnect when closed#5272ravi-arnan wants to merge 1 commit into
ravi-arnan wants to merge 1 commit into
Conversation
…n closed The module took its connection from g_bus_get_sync(), which returns the process-wide shared system bus, and its destructor closed that connection. Destroying an Inhibitor therefore closes the shared connection for the whole process, and GLib keeps handing the same closed connection back to every later g_bus_get_sync() caller, so the module built for the next bar can never take a lock again: every toggle fails with "The connection is closed" until waybar is restarted. A bar is destroyed and rebuilt whenever its output goes away and comes back (Client::handleDeferredMonitorRemoval), which is what happens across suspend/resume, so the inhibitor stops working after a sleep. Open a private connection that the module owns and may close, and re-establish it when it is found closed. Closes Alexays#5260
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
The inhibitor module took its connection from
g_bus_get_sync(), which returns the process-wide shared system bus, and its destructor calledg_dbus_connection_close_sync()on it. Destroying an Inhibitor therefore closes the shared connection for the whole process, and GLib keeps handing that same closed connection back to every laterg_bus_get_sync()caller, so the Inhibitor built for the next bar starts life holding a dead connection with no way to get a live one. Every toggle then fails withThe connection is closeduntil waybar is restarted.A bar is destroyed and rebuilt whenever its output goes away and comes back (
Client::handleDeferredMonitorRemoval), which is what happens across suspend/resume. That is why #5260 shows up after a sleep.This opens a private system bus connection that the module owns and may legitimately close, and re-establishes it when it is found closed.
Related issues
Closes #5260
How to reproduce and verify
No suspend needed, cycling the output is enough. Bar with only the inhibitor module,
systemd-inhibit --listas ground truth for whether the lock was really taken, clicks injected through the compositor rather than by hand:master(d561b9d)g_dbus_connection_call_with_unix_fd_list_sync() failed: The connection is closed+cannot get inhibitor locksWhy the connection can never be re-acquired on master
A short GIO program on the same machine: take the shared system bus, close it the way the destructor does, iterate the main context, ask for it again. GLib returns the identical pointer with
is_closed = 1, so "just callg_bus_get_sync()again" is not a fix. That is what makes a private connection the right shape here.Second case, a genuine peer-side drop
Running waybar against a pass-through dbus proxy and killing the proxy, again with only the inhibitor module configured:
masterg_bus_get_sync()connections haveexit-on-close)Worth stating precisely: waybar surviving that drop is a property of this test config. Other modules still take the shared bus through
g_bus_get_sync(), so a real config with them present will still exit on a bus drop. Nothing here changes that, it only stops the inhibitor from breaking the shared connection for everyone else.Checklist
clang-format(--dry-run --Werrorclean on both touched files)ninja -C build)meson test -C build: 3/3 ok, plus the two live A/B runs above)Tested on NixOS 26.11, GLib 2.88.3, GTK 3, niri 26.04, single output.