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

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