Blob Blame History Raw
From 3d16b5fb23c4a41ba15a1e8dfdcd2b302557c377 Mon Sep 17 00:00:00 2001
From: Adam Williamson <awilliam@redhat.com>
Date: Tue, 13 Apr 2021 09:02:55 -0700
Subject: [PATCH] Re-connect to dbus for each call (POO #90872)

By using the system bus and leaving our connection to it open
for the entire lifetime of the isotovideo process, we're setting
ourselves up to receive a lot of signals we don't deal with, and
just letting them accumulate. Since all we want to do is send a
signal and then go away, let's use a private socket, and
re-initialize the connection for each signal. The overhead of
doing this is not large, and we're sending small numbers of
signals per isotovideo process anyway (one signal per network on
startup, one signal at startup if a debug variable is set, and
one signal per network at end).

Thanks to @dvdhrm and @berrange for their help with this.

Signed-off-by: Adam Williamson <awilliam@redhat.com>
---
 backend/qemu.pm | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/backend/qemu.pm b/backend/qemu.pm
index 6c64f497..b847ddd1 100644
--- a/backend/qemu.pm
+++ b/backend/qemu.pm
@@ -135,10 +135,11 @@ sub stop_qemu {
 
 sub _dbus_do_call {
     my ($self, $fn, @args) = @_;
-    $self->{dbus}         ||= Net::DBus->system;
-    $self->{dbus_service} ||= $self->{dbus}->get_service("org.opensuse.os_autoinst.switch");
-    $self->{dbus_object}  ||= $self->{dbus_service}->get_object("/switch", "org.opensuse.os_autoinst.switch");
-    $self->{dbus_object}->$fn(@args);
+    my $bus         = Net::DBus->system(private => "true");
+    my $bus_service = $bus->get_service("org.opensuse.os_autoinst.switch");
+    my $bus_object  = $bus_service->get_object("/switch", "org.opensuse.os_autoinst.switch");
+    $bus_object->$fn(@args);
+    $bus->get_connection->disconnect;
 }
 
 sub _dbus_call {
-- 
2.31.1