From 23c4aef64799eb563f63a51fe8fc7f2ae58dc17b Mon Sep 17 00:00:00 2001 From: Felix Moessbauer Date: Thu, 19 Sep 2024 14:34:03 +0200 Subject: [PATCH] fix: poll for introspection data on startup Starting the DBus service via systemd and getting the introspection data is a non atomic operation. The start call can return before the service is fully running. As the introspection data is acquired from the DBus service and not from the broker service, this call is not delayed until the service is responding. This exposes a more fundamental issue: Introspection and DBus activation is simply incompatible. To mitigate this, we retry the introspection for some time after startup. Signed-off-by: Felix Moessbauer --- linux-entra-sso.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/linux-entra-sso.py b/linux-entra-sso.py index f34dbe8..f8a18bd 100755 --- a/linux-entra-sso.py +++ b/linux-entra-sso.py @@ -13,6 +13,7 @@ import struct import uuid import ctypes +import time from signal import SIGINT from threading import Thread, Lock from gi.repository import GLib @@ -27,6 +28,7 @@ # value can be used, if no real value is provided. SSO_URL_DEFAULT = "https://login.microsoftonline.com/" EDGE_BROWSER_CLIENT_ID = "d7b530a4-7680-4c23-a8bf-c52c121d2e87" +BROKER_START_TIMEOUT = 5 # dbus start service reply codes START_REPLY_SUCCESS = 1 START_REPLY_ALREADY_RUNNING = 2 @@ -94,7 +96,13 @@ def _check_broker_online(self): self.broker_online = False def _instantiate_broker(self): - self.broker = self._bus.get(self.BROKER_NAME, self.BROKER_PATH) + timeout = time.time() + BROKER_START_TIMEOUT + while not self.broker and time.time() < timeout: + try: + self.broker = self._bus.get(self.BROKER_NAME, self.BROKER_PATH) + except GLib.Error: + time.sleep(0.1) + pass def _monitor_bus(self): self._bus.subscribe(