core/dbus: do not block the manager on GetId during bus (re-)connection

bus_init_api() issued a synchronous GetId call on every API bus
(re-)connection to decide whether saved subscription state could be
coldplugged onto the new connection.

If the D-Bus socket unit is listening while the message bus daemon
behind it is gone, connect() succeeds against the socket backlog but
nothing answers the authentication handshake. The synchronous call
then blocks PID 1 for BUS_AUTH_TIMEOUT (90 seconds by default), and
queued bus operations can trigger repeated reconnection attempts.
This was observed during shutdown as roughly 15 minutes of teardown
progressing only in 90-second intervals.

Query the instance ID asynchronously on every connection. Defer API
setup until the reply is processed, so saved subscriptions are
validated and coldplugged before new subscription requests can arrive.
If the query cannot be queued or its reply is invalid, discard the
unvalidated state and expose the API without blocking the manager.

Reset the live bus ID on every connection and serialize pending bus ID
and subscription state across reload and reexec. During daemon-reload,
preserve state that was already awaiting the asynchronous reply while
discarding the duplicate state produced by the reload itself.

Also remove the now-unused synchronous bus_get_instance_id() helper.
This commit is contained in:
Sinity
2026-07-20 11:53:34 +09:00
committed by Yu Watanabe
parent d751846043
commit 1166f4472d
5 changed files with 109 additions and 39 deletions
-23
View File
@@ -10,7 +10,6 @@
#include "sd-bus.h"
#include "sd-daemon.h"
#include "sd-event.h"
#include "sd-id128.h"
#include "alloc-util.h"
#include "bus-common-errors.h"
@@ -916,28 +915,6 @@ int bus_query_sender_pidref(
return bus_creds_get_pidref(creds, ret);
}
int bus_get_instance_id(sd_bus *bus, sd_id128_t *ret) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
int r;
assert(bus);
assert(ret);
r = sd_bus_call_method(bus,
"org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "GetId",
/* reterr_error= */ NULL, &reply, NULL);
if (r < 0)
return r;
const char *id;
r = sd_bus_message_read_basic(reply, 's', &id);
if (r < 0)
return r;
return sd_id128_from_string(id, ret);
}
static const char* const bus_transport_table[] = {
[BUS_TRANSPORT_LOCAL] = "local",
[BUS_TRANSPORT_REMOTE] = "remote",
-2
View File
@@ -70,6 +70,4 @@ int bus_register_malloc_status(sd_bus *bus, const char *destination);
int bus_creds_get_pidref(sd_bus_creds *c, PidRef *ret);
int bus_query_sender_pidref(sd_bus_message *m, PidRef *ret);
int bus_get_instance_id(sd_bus *bus, sd_id128_t *ret);
DECLARE_STRING_TABLE_LOOKUP_TO_STRING(bus_transport, BusTransport);