Blame SOURCES/0008-Detect-timeout-conditions-more-aggressively-on-Linux.patch

9cad3f
From 9e9f2b81652d2ed551e9f890d27cf5a0da6ba5f6 Mon Sep 17 00:00:00 2001
9cad3f
From: Jeremy White <jwhite@codeweavers.com>
9cad3f
Date: Tue, 30 Apr 2019 17:04:59 -0500
9cad3f
Subject: [PATCH] Detect timeout conditions more aggressively on Linux
9cad3f
9cad3f
This mitigates a fairly rare problem we see with our kiosk mode clients.
9cad3f
That is, normally if something goes wrong with a client connection
9cad3f
(e.g. the session is killed, or the server is restarted ), the kiosk will
9cad3f
exit on disconnect, and we get a chance to retry the connection, or
9cad3f
present the user with a 'server down' style message.
9cad3f
9cad3f
But in the case of a serious network problem or a server hard power
9cad3f
cycle (i.e. no TCP FIN packets can flow), our end user behavior is not
9cad3f
ideal - the kiosk appears to hang solid, requiring a power cycle.
9cad3f
9cad3f
That's because we've got the stock keepalive timeouts, or about 2 hours
9cad3f
and 11 minutes, before the client sees the disconnect.
9cad3f
9cad3f
This change will cause the client to recognize the server has vanished
9cad3f
without a TCP FIN after 75 seconds.
9cad3f
9cad3f
See this thread:
9cad3f
  https://lists.freedesktop.org/archives/spice-devel/2017-March/036553.html
9cad3f
9cad3f
As well as this bug:
9cad3f
  https://bugzilla.redhat.com/show_bug.cgi?id=1436589
9cad3f
9cad3f
Signed-off-by: Jeremy White <jwhite@codeweavers.com>
9cad3f
(cherry picked from commit 677782fb6aa471d5e6d007744a5c6564b1f3021f)
9cad3f
---
9cad3f
 src/spice-session.c | 26 ++++++++++++++++++++++++++
9cad3f
 1 file changed, 26 insertions(+)
9cad3f
9cad3f
diff --git a/src/spice-session.c b/src/spice-session.c
9cad3f
index ee6e4cf..59c20c7 100644
9cad3f
--- a/src/spice-session.c
9cad3f
+++ b/src/spice-session.c
9cad3f
@@ -17,6 +17,8 @@
9cad3f
 */
9cad3f
 #include "config.h"
9cad3f
 
9cad3f
+/* include first, on Windows will override winsock definitions */
9cad3f
+#include <gio/gnetworking.h>
9cad3f
 #include <gio/gio.h>
9cad3f
 #include <glib.h>
9cad3f
 #ifdef G_OS_UNIX
9cad3f
@@ -39,6 +41,13 @@ struct channel {
9cad3f
     RingItem          link;
9cad3f
 };
9cad3f
 
9cad3f
+#if !defined(SOL_TCP) && defined(IPPROTO_TCP)
9cad3f
+#define SOL_TCP IPPROTO_TCP
9cad3f
+#endif
9cad3f
+#if !defined(TCP_KEEPIDLE) && defined(TCP_KEEPALIVE) && defined(__APPLE__)
9cad3f
+#define TCP_KEEPIDLE TCP_KEEPALIVE
9cad3f
+#endif
9cad3f
+
9cad3f
 #define IMAGES_CACHE_SIZE_DEFAULT (1024 * 1024 * 80)
9cad3f
 #define MIN_GLZ_WINDOW_SIZE_DEFAULT (1024 * 1024 * 12)
9cad3f
 #define MAX_GLZ_WINDOW_SIZE_DEFAULT MIN((LZ_MAX_WINDOW_SIZE * 4), 1024 * 1024 * 64)
9cad3f
@@ -2233,6 +2242,23 @@ GSocketConnection* spice_session_channel_open_host(SpiceSession *session, SpiceC
9cad3f
         g_socket_set_timeout(socket, 0);
9cad3f
         g_socket_set_blocking(socket, FALSE);
9cad3f
         g_socket_set_keepalive(socket, TRUE);
9cad3f
+
9cad3f
+        /* Make client timeouts a bit more responsive */
9cad3f
+#if defined(_WIN32)
9cad3f
+        /*  Windows does not support setting count */
9cad3f
+        struct tcp_keepalive keepalive = {
9cad3f
+            TRUE,
9cad3f
+            30 * 1000,
9cad3f
+            5 * 1000
9cad3f
+        };
9cad3f
+        DWORD written;
9cad3f
+        WSAIoctl(g_socket_get_fd(socket), SIO_KEEPALIVE_VALS, &keepalive, sizeof(keepalive),
9cad3f
+                 NULL, 0, &written, NULL, NULL);
9cad3f
+#elif defined(TCP_KEEPIDLE) && defined(TCP_KEEPINTVL)
9cad3f
+        g_socket_set_option(socket, SOL_TCP, TCP_KEEPIDLE, 30, NULL);
9cad3f
+        g_socket_set_option(socket, SOL_TCP, TCP_KEEPINTVL, 15, NULL);
9cad3f
+        g_socket_set_option(socket, SOL_TCP, TCP_KEEPCNT, 3, NULL);
9cad3f
+#endif
9cad3f
     }
9cad3f
 
9cad3f
     g_clear_object(&open_host.client);
9cad3f
-- 
9cad3f
2.21.0
9cad3f