Blame SOURCES/0020-vdagent-udscs-limit-retry-to-connect-to-vdagentd.patch

583950
From 1aa2c06015e15f707ba9f874d5a5ea49fd450745 Mon Sep 17 00:00:00 2001
583950
From: Victor Toso <victortoso@redhat.com>
583950
Date: Wed, 1 Dec 2021 20:07:22 +0100
583950
Subject: [PATCH 20/21] vdagent: udscs: limit retry to connect to vdagentd
583950
583950
Related: https://bugzilla.redhat.com/show_bug.cgi?id=2005802
583950
Related: https://bugzilla.redhat.com/show_bug.cgi?id=2028013
583950
Signed-off-by: Victor Toso <victortoso@redhat.com>
583950
---
583950
 src/vdagent/vdagent.c | 21 +++++++++++++++++++++
583950
 1 file changed, 21 insertions(+)
583950
583950
diff --git a/src/vdagent/vdagent.c b/src/vdagent/vdagent.c
583950
index fd08522..0d3945e 100644
583950
--- a/src/vdagent/vdagent.c
583950
+++ b/src/vdagent/vdagent.c
583950
@@ -42,11 +42,14 @@
583950
 #include "clipboard.h"
583950
 #include "display.h"
583950
 
583950
+#define MAX_RETRY_CONNECT_SYSTEM_AGENT 60
583950
+
583950
 typedef struct VDAgent {
583950
     VDAgentClipboards *clipboards;
583950
     VDAgentDisplay *display;
583950
     struct vdagent_file_xfers *xfers;
583950
     UdscsConnection *conn;
583950
+    gint udscs_num_retry;
583950
 
583950
     GMainLoop *loop;
583950
 } VDAgent;
583950
@@ -378,9 +381,27 @@ static gboolean vdagent_init_async_cb(gpointer user_data)
583950
                                 daemon_read_complete, daemon_error_cb,
583950
                                 debug);
583950
     if (agent->conn == NULL) {
583950
+        if (agent->udscs_num_retry == MAX_RETRY_CONNECT_SYSTEM_AGENT) {
583950
+            syslog(LOG_WARNING,
583950
+                   "Failed to connect to spice-vdagentd at %s (tried %d times)",
583950
+                   vdagentd_socket, agent->udscs_num_retry);
583950
+            goto err_init;
583950
+        }
583950
+        if (agent->udscs_num_retry == 0) {
583950
+            /* Log only when it fails and at the end */
583950
+            syslog(LOG_DEBUG,
583950
+                   "Failed to connect with spice-vdagentd. Trying again in 1s");
583950
+        }
583950
+        agent->udscs_num_retry++;
583950
         g_timeout_add_seconds(1, vdagent_init_async_cb, agent);
583950
         return G_SOURCE_REMOVE;
583950
     }
583950
+    if (agent->udscs_num_retry != 0) {
583950
+        syslog(LOG_DEBUG,
583950
+               "Connected with spice-vdagentd after %d attempts",
583950
+               agent->udscs_num_retry);
583950
+    }
583950
+    agent->udscs_num_retry = 0;
583950
     g_object_set_data(G_OBJECT(agent->conn), "agent", agent);
583950
 
583950
     agent->display = vdagent_display_create(agent->conn, debug, x11_sync);
583950
-- 
583950
2.33.1
583950