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

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