qtvcp: close dbus bus when sys_notify init fails#4064
Merged
BsAtHome merged 1 commit intoMay 28, 2026
Conversation
If `init()` constructs `dbus.SessionBus(mainloop)` with the PyQt5/PyQt6 mainloop integration and the subsequent `bus.get_object(org.freedesktop.Notifications, ...)` call raises (e.g. `org.freedesktop.DBus.Error.ServiceUnknown` when no notification daemon owns the name), the Python reference to `bus` is dropped on the exception, but dbus-python's mainloop layer has already attached a `QSocketNotifier` to the connection fd. That notifier keeps the C-level connection alive in a half-initialized state. On the next Qt event-loop tick, the queued reply is dispatched via `dbus_connection_dispatch()` and segfaults inside `_dbus_list_unlink` because the connection's internal queue is no longer in a consistent state. Close the bus explicitly on the failure path so the socket notifier detaches and the connection is released cleanly. The `Desktop Notify not available` warning continues to be the only user-visible side effect. Reproduced on Ubuntu 24.04 CI under xvfb + offscreen Qt where no session-bus notification daemon is present; gdb -batch captured a Thread 1 backtrace ending in `dbus_connection_dispatch` -> `_dbus_list_pop_first_link` -> `_dbus_list_unlink` (segv).
5 tasks
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.
Summary
lib/python/qtvcp/lib/sys_notify.pyconstructs adbus.SessionBuswith the PyQt5 (or PyQt6) mainloop integration before probing for
org.freedesktop.Notifications. When the probe raises (e.g.org.freedesktop.DBus.Error.ServiceUnknownbecause no notificationdaemon owns the name on the session bus), the Python
busreferenceis dropped on the exception but the mainloop layer has already
attached a
QSocketNotifierto the connection's fd. That keeps theC-level connection alive in a half-initialized state. On the next
Qt event-loop tick the queued message is dispatched via
dbus_connection_dispatch()and segfaults inside_dbus_list_unlinkbecause the connection's internal queue is nolonger consistent.
Closing the bus on the failure path detaches the notifier and lets
the connection be released. The
Desktop Notify not availablewarning continues to be the only user-visible side effect.
Repro
Ubuntu 24.04 GitHub runner with xvfb +
QT_QPA_PLATFORM=offscreenand no session-bus notification daemon. Surfaced during PR #4054
qtdragon ui-smoke; captured under
gdb -batch(Thread 1 only):Same investigation surfaced PR #4062 (shutdown-time
hal_exituse-after-free in QPin timer). The two are independent: #4062 is
the teardown path, this is the startup path.
Test plan
_dbus_list_unlinkonUbuntu 24.04 (PR test: ui-smoke phase 2, g-code execution and endpoint check #4054 CI runs 26561722252, 26572207672)
71s (matches pre-regression baseline)
python3 -m py_compile lib/python/qtvcp/lib/sys_notify.pyclean
Risk
The new
exceptbranch only runs when init has already failed.bus.close()is the documented teardown fordbus.Connection;swallowing exceptions from it is safe because the connection is
already being abandoned.