<html><body><div style="font-family: times new roman, new york, times, serif; font-size: 12pt; color: #000000"><div><br></div><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;" data-mce-style="border-left: 2px solid #1010FF; margin-left: 5px; padding-left: 5px; color: #000; font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica,Arial,sans-serif; font-size: 12pt;"><div dir="ltr"><div><div><br></div><div>Hi,</div><div><br></div><div>With firewall running between spice server and client, if idle time is larger than firewall session timeout, spice sessions freeze and users lose their keyboard and mouse control.</div><div><br></div><div>To workaround this issue, I made a patch to add tcp keepalive timeout to spice server. The timeout can be added to qemu config like below.</div><div>    <domain type='kvm' xmlns:qemu='<a href="http://libvirt.org/schemas/domain/qemu/1.0" target="_blank" data-mce-href="http://libvirt.org/schemas/domain/qemu/1.0">http://libvirt.org/schemas/domain/qemu/1.0</a>'></div><div>      <qemu:commandline></div><div>        <qemu:env name='SPICE_KEEPALIVE_TIMEOUT' value='1800'/></div><div>      </qemu:commandline></div><div><br></div><div>I wanted to add this option to spice client, but there was no setsockopt() option of TCP_KEEPIDLE for windows platform, So, I ended up adding it to spice server. Please review the patch and let me know what you think. Thank you.</div></div></div></blockquote><div><br></div><div>For Windows see <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ee470551%28v=vs.85%29.aspx,">https://msdn.microsoft.com/en-us/library/windows/desktop/ee470551%28v=vs.85%29.aspx,</a> are used SO_KEEPALIVE and SIO_KEEPALIVE_VALS.<br></div><div><br></div><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;" data-mce-style="border-left: 2px solid #1010FF; margin-left: 5px; padding-left: 5px; color: #000; font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica,Arial,sans-serif; font-size: 12pt;"><div dir="ltr"><div><div>---------------------------------------------------------------------------------------------------</div><div>[PATCH 1/1] channel: add optional tcp keepalive timeout to channels</div><div><br></div><div>Signed-off-by: Sunny Shin <<a href="mailto:sunny4s.git@gmail.com" target="_blank" data-mce-href="mailto:sunny4s.git@gmail.com">sunny4s.git@gmail.com</a>></div><div>---</div><div> server/reds.c | 28 ++++++++++++++++++++++++++++</div><div> 1 file changed, 28 insertions(+)</div><div><br></div><div>diff --git a/server/reds.c b/server/reds.c</div><div>index 8b3c3cb..05d0b1d 100644</div><div>--- a/server/reds.c</div><div>+++ b/server/reds.c</div><div>@@ -2254,6 +2254,9 @@ static RedLinkInfo *reds_init_client_connection(int socket)</div><div>     RedLinkInfo *link;</div><div>     int delay_val = 1;</div><div>     int flags;</div><div>+    char *keepalive_timeout_str;</div><div>+    int keepalive_timeout;</div><div>+    int keepalive = 1;</div><div><br></div><div>     if ((flags = fcntl(socket, F_GETFL)) == -1) {</div><div>         spice_warning("accept failed, %s", strerror(errno));</div><div>@@ -2271,6 +2274,31 @@ static RedLinkInfo *reds_init_client_connection(int socket)</div><div>         }</div><div>     }</div><div><br></div><div>+    keepalive_timeout_str = getenv("SPICE_KEEPALIVE_TIMEOUT");</div></div></div></blockquote><div>See Djasa comment, environment are not good here.<br></div><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;" data-mce-style="border-left: 2px solid #1010FF; margin-left: 5px; padding-left: 5px; color: #000; font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica,Arial,sans-serif; font-size: 12pt;"><div dir="ltr"><div><div>+    if (keepalive_timeout_str != NULL) {</div><div>+        errno = 0;</div><div>+        keepalive_timeout = strtol(keepalive_timeout_str, NULL, 10);</div><div>+        if (errno != 0) {</div><div>+            spice_warning("error parsing SPICE_KEEPALIVE_TIMEOUT: %s", strerror(errno));</div><div>+            goto error;</div><div>+        }</div><div>+</div><div>+        spice_debug("keepalive timeout %ds", keepalive_timeout);</div><div>+        if (setsockopt(socket, SOL_SOCKET, SO_KEEPALIVE, &keepalive, sizeof(keepalive)) == -1) {</div><div>+            if (errno != ENOTSUP) {</div><div>+                spice_printerr("setsockopt for keepalive failed, %s", strerror(errno));</div><div>+                goto error;</div><div>+            }</div><div>+        }</div></div></div></blockquote><div>I would just issue a warning on error and keep going (not jump to error), we can live without keepalive<br></div><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;" data-mce-style="border-left: 2px solid #1010FF; margin-left: 5px; padding-left: 5px; color: #000; font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica,Arial,sans-serif; font-size: 12pt;"><div dir="ltr"><div><div>+        if (setsockopt(socket, SOL_TCP, TCP_KEEPIDLE,</div><div>+                       &keepalive_timeout, sizeof(keepalive_timeout)) == -1) {</div><div>+            if (errno != ENOTSUP) {</div><div>+                spice_printerr("setsockopt for keepalive timeout failed, %s", strerror(errno));</div><div>+                goto error;</div><div>+            }</div><div>+        }</div></div></div></blockquote><div>same here.<br></div><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;" data-mce-style="border-left: 2px solid #1010FF; margin-left: 5px; padding-left: 5px; color: #000; font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica,Arial,sans-serif; font-size: 12pt;"><div dir="ltr"><div><div>+    }</div><div>+</div><div>     link = spice_new0(RedLinkInfo, 1);</div><div>     link->stream = reds_stream_new(socket);</div></div></div></blockquote><div>Frediano</div><div><br></div></div></body></html>