diff --git a/lib/python/qtvcp/lib/sys_notify.py b/lib/python/qtvcp/lib/sys_notify.py index 839447bc6aa..17879358697 100644 --- a/lib/python/qtvcp/lib/sys_notify.py +++ b/lib/python/qtvcp/lib/sys_notify.py @@ -62,6 +62,7 @@ def init(app_name): interface = "org.freedesktop.Notifications" mainloop = None + bus = None try: if DBusQtMainLoop is not None: mainloop = DBusQtMainLoop(set_as_default=True) @@ -76,6 +77,23 @@ def init(app_name): DBUS_IFACE.connect_to_signal('NotificationClosed', _onNotificationClosed) except Exception as e: LOG.warning('Desktop Notify not available:: {}'.format(e)) + # When the SessionBus is constructed with a PyQt5/PyQt6 mainloop + # integration, dbus-python installs a QSocketNotifier on the + # connection fd. If the subsequent get_object/Interface setup + # raises (e.g. ServiceUnknown when no notification daemon owns + # org.freedesktop.Notifications), the Python-side bus reference + # is dropped on exception but the QSocketNotifier keeps the + # underlying C connection alive in a half-initialized state. + # The next QEventLoop tick dispatches a queued message via + # dbus_connection_dispatch() and segfaults inside + # _dbus_list_unlink. Close the bus explicitly so the notifier + # detaches and the connection is fully released. + DBUS_IFACE = None + if bus is not None: + try: + bus.close() + except Exception: + pass def _onActionInvoked(nid, action):