[Spice-commits] src/spice-session.c

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed May 1 15:47:52 UTC 2019


 src/spice-session.c |   26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

New commits:
commit 677782fb6aa471d5e6d007744a5c6564b1f3021f
Author: Jeremy White <jwhite at codeweavers.com>
Date:   Tue Apr 30 17:04:59 2019 -0500

    Detect timeout conditions more aggressively on Linux
    
    This mitigates a fairly rare problem we see with our kiosk mode clients.
    That is, normally if something goes wrong with a client connection
    (e.g. the session is killed, or the server is restarted ), the kiosk will
    exit on disconnect, and we get a chance to retry the connection, or
    present the user with a 'server down' style message.
    
    But in the case of a serious network problem or a server hard power
    cycle (i.e. no TCP FIN packets can flow), our end user behavior is not
    ideal - the kiosk appears to hang solid, requiring a power cycle.
    
    That's because we've got the stock keepalive timeouts, or about 2 hours
    and 11 minutes, before the client sees the disconnect.
    
    This change will cause the client to recognize the server has vanished
    without a TCP FIN after 75 seconds.
    
    See this thread:
      https://lists.freedesktop.org/archives/spice-devel/2017-March/036553.html
    
    As well as this bug:
      https://bugzilla.redhat.com/show_bug.cgi?id=1436589
    
    Signed-off-by: Jeremy White <jwhite at codeweavers.com>

diff --git a/src/spice-session.c b/src/spice-session.c
index 8952897..04ba124 100644
--- a/src/spice-session.c
+++ b/src/spice-session.c
@@ -17,6 +17,8 @@
 */
 #include "config.h"
 
+/* include first, on Windows will override winsock definitions */
+#include <gio/gnetworking.h>
 #include <gio/gio.h>
 #include <glib.h>
 #ifdef G_OS_UNIX
@@ -33,6 +35,13 @@
 #include "channel-playback-priv.h"
 #include "spice-audio-priv.h"
 
+#if !defined(SOL_TCP) && defined(IPPROTO_TCP)
+#define SOL_TCP IPPROTO_TCP
+#endif
+#if !defined(TCP_KEEPIDLE) && defined(TCP_KEEPALIVE) && defined(__APPLE__)
+#define TCP_KEEPIDLE TCP_KEEPALIVE
+#endif
+
 #define IMAGES_CACHE_SIZE_DEFAULT (1024 * 1024 * 80)
 #define MIN_GLZ_WINDOW_SIZE_DEFAULT (1024 * 1024 * 12)
 #define MAX_GLZ_WINDOW_SIZE_DEFAULT MIN((LZ_MAX_WINDOW_SIZE * 4), 1024 * 1024 * 64)
@@ -2254,6 +2263,23 @@ GSocketConnection* spice_session_channel_open_host(SpiceSession *session, SpiceC
         g_socket_set_timeout(socket, 0);
         g_socket_set_blocking(socket, FALSE);
         g_socket_set_keepalive(socket, TRUE);
+
+        /* Make client timeouts a bit more responsive */
+#if defined(_WIN32)
+        /*  Windows does not support setting count */
+        struct tcp_keepalive keepalive = {
+            TRUE,
+            30 * 1000,
+            5 * 1000
+        };
+        DWORD written;
+        WSAIoctl(g_socket_get_fd(socket), SIO_KEEPALIVE_VALS, &keepalive, sizeof(keepalive),
+                 NULL, 0, &written, NULL, NULL);
+#elif defined(TCP_KEEPIDLE) && defined(TCP_KEEPINTVL)
+        g_socket_set_option(socket, SOL_TCP, TCP_KEEPIDLE, 30, NULL);
+        g_socket_set_option(socket, SOL_TCP, TCP_KEEPINTVL, 15, NULL);
+        g_socket_set_option(socket, SOL_TCP, TCP_KEEPCNT, 3, NULL);
+#endif
     }
 
     g_clear_object(&open_host.client);


More information about the Spice-commits mailing list