diff --git a/src/core/dbus-job.c b/src/core/dbus-job.c index 9792a5c44a..c88d8c2dd5 100644 --- a/src/core/dbus-job.c +++ b/src/core/dbus-job.c @@ -241,6 +241,9 @@ void bus_job_send_change_signal(Job *j) { if (j->in_dbus_queue) { LIST_REMOVE(dbus_queue, j->manager->dbus_job_queue, j); j->in_dbus_queue = false; + + /* The job might be good to be GC once its pending signals have been sent */ + job_add_to_gc_queue(j); } r = bus_foreach_bus(j->manager, j->bus_track, j->sent_dbus_new_signal ? send_changed_signal : send_new_signal, j); diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c index b45b3fdb53..9d3c3be4e9 100644 --- a/src/core/dbus-unit.c +++ b/src/core/dbus-unit.c @@ -1629,6 +1629,9 @@ void bus_unit_send_change_signal(Unit *u) { if (u->in_dbus_queue) { LIST_REMOVE(dbus_queue, u->manager->dbus_unit_queue, u); u->in_dbus_queue = false; + + /* The unit might be good to be GC once its pending signals have been sent */ + unit_add_to_gc_queue(u); } if (!u->id) diff --git a/src/core/job.c b/src/core/job.c index 032554a0ac..bd3a741ffd 100644 --- a/src/core/job.c +++ b/src/core/job.c @@ -1407,6 +1407,10 @@ bool job_may_gc(Job *j) { if (!UNIT_VTABLE(j->unit)->gc_jobs) return false; + /* Make sure to send out pending D-Bus events before we unload the unit */ + if (j->in_dbus_queue) + return false; + if (sd_bus_track_count(j->bus_track) > 0) return false; diff --git a/src/core/unit.c b/src/core/unit.c index 4360351bd9..03eb3aaecf 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -423,6 +423,10 @@ bool unit_may_gc(Unit *u) { if (u->in_cgroup_empty_queue || u->in_cgroup_oom_queue) return false; + /* Make sure to send out D-Bus events before we unload the unit */ + if (u->in_dbus_queue) + return false; + if (sd_bus_track_count(u->bus_track) > 0) return false;