Blame SOURCES/0037-Add-TCP-level-timeout-to-LDAP-services.patch

ef0222
From bad7c631b7aab50d179755ee546357e4f4faca9d Mon Sep 17 00:00:00 2001
ef0222
From: Simo Sorce <simo@redhat.com>
ef0222
Date: Tue, 10 Sep 2019 14:33:37 +0000
ef0222
Subject: [PATCH] Add TCP level timeout to LDAP services
ef0222
ef0222
In some cases the TCP connection may hang with data sent because
ef0222
of network conditions, this may cause the socket to stall for much
ef0222
longer than the timeout intended.
ef0222
Set a TCP option to forcibly timeout a socket that sees its data not
ef0222
ACKed within the ldap_network_timeout seconds.
ef0222
ef0222
Signed-off-by: Simo Sorce <simo@redhat.com>
ef0222
ef0222
Reviewed-by: Sumit Bose <sbose@redhat.com>
ef0222
(cherry picked from commit 7aa96458f3bec4ef6ff7385107458e6b2b0b06ac)
ef0222
---
ef0222
 src/util/sss_sockets.c | 11 +++++++++++
ef0222
 1 file changed, 11 insertions(+)
ef0222
ef0222
diff --git a/src/util/sss_sockets.c b/src/util/sss_sockets.c
ef0222
index 0e4d8df8a..b6b6dbac5 100644
ef0222
--- a/src/util/sss_sockets.c
ef0222
+++ b/src/util/sss_sockets.c
ef0222
@@ -79,6 +79,7 @@ static errno_t set_fd_common_opts(int fd, int timeout)
ef0222
     int dummy = 1;
ef0222
     int ret;
ef0222
     struct timeval tv;
ef0222
+    unsigned int milli;
ef0222
 
ef0222
     /* SO_KEEPALIVE and TCP_NODELAY are set by OpenLDAP client libraries but
ef0222
      * failures are ignored.*/
ef0222
@@ -117,6 +118,16 @@ static errno_t set_fd_common_opts(int fd, int timeout)
ef0222
                   "setsockopt SO_SNDTIMEO failed.[%d][%s].\n", ret,
ef0222
                   strerror(ret));
ef0222
         }
ef0222
+
ef0222
+        milli = timeout * 1000; /* timeout in milliseconds */
ef0222
+        ret = setsockopt(fd, IPPROTO_TCP, TCP_USER_TIMEOUT, milli,
ef0222
+                         sizeof(milli));
ef0222
+        if (ret != 0) {
ef0222
+            ret = errno;
ef0222
+            DEBUG(SSSDBG_FUNC_DATA,
ef0222
+                  "setsockopt TCP_USER_TIMEOUT failed.[%d][%s].\n", ret,
ef0222
+                  strerror(ret));
ef0222
+        }
ef0222
     }
ef0222
 
ef0222
     return EOK;
ef0222
-- 
ef0222
2.20.1
ef0222