Blob Blame History Raw
From 1c22f827790577e7bd9a7b9a0d75c8657f4d4e1c Mon Sep 17 00:00:00 2001
From: Christophe Fergeau <cfergeau@redhat.com>
Date: Thu, 15 Oct 2015 16:45:59 +0200
Subject: [PATCH] Stop polling after reconnecting to libvirtd

When the connection to libvirtd is lost, virt-viewer starts polling for
libvirtd to come back. The polling mechanism is also used when
connecting to very old libvirtd which don't support
virConnectDomainEventDeregisterAny().

Currently, once we could reconnect to libvirtd, virt-viewer will keep
polling, thus behaving as if the libvirtd connection does not support
virConnectDomainEventDeregisterAny(). This commit makes sure we stop
polling once the new libvirtd connection is established.

This has the side-effect of preventing
https://bugzilla.redhat.com/show_bug.cgi?id=1271519 from occurring with
recent libvirt as it's caused by some race occurring when using the
polling code.

(cherry picked from commit c1e72c1be177544e5a718303dcb88412568f46d9)
---
 src/virt-viewer.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/src/virt-viewer.c b/src/virt-viewer.c
index bcac2ca..cba1e51 100644
--- a/src/virt-viewer.c
+++ b/src/virt-viewer.c
@@ -151,6 +151,20 @@ virt_viewer_start_reconnect_poll(VirtViewer *self)
 }
 
 static void
+virt_viewer_stop_reconnect_poll(VirtViewer *self)
+{
+    VirtViewerPrivate *priv = self->priv;
+
+    g_debug("reconnect_poll: %d", priv->reconnect_poll);
+
+    if (priv->reconnect_poll == 0)
+        return;
+
+    g_source_remove(priv->reconnect_poll);
+    priv->reconnect_poll = 0;
+}
+
+static void
 virt_viewer_deactivated(VirtViewerApp *app, gboolean connect_error)
 {
     VirtViewer *self = VIRT_VIEWER(app);
@@ -952,6 +966,10 @@ virt_viewer_connect(VirtViewerApp *app, GError **err)
         !virt_viewer_app_is_active(app)) {
         g_debug("No domain events, falling back to polling");
         virt_viewer_start_reconnect_poll(self);
+    } else {
+        /* we may be polling if we lost the libvirt connection and are trying
+         * to reconnect */
+        virt_viewer_stop_reconnect_poll(self);
     }
 
     if (virConnectRegisterCloseCallback(priv->conn,