Blame SOURCES/0187-RESPONDERS-Fix-terminating-idle-connections.patch

8974b2
From d6c7d35fdb4d416360a855a37b8c2164f053b470 Mon Sep 17 00:00:00 2001
8974b2
From: Jakub Hrozek <jhrozek@redhat.com>
8974b2
Date: Tue, 11 Jul 2017 18:26:01 +0200
8974b2
Subject: [PATCH 187/190] RESPONDERS: Fix terminating idle connections
8974b2
MIME-Version: 1.0
8974b2
Content-Type: text/plain; charset=UTF-8
8974b2
Content-Transfer-Encoding: 8bit
8974b2
8974b2
The client_idle_handler() function tried to schedule another tevent
8974b2
timer to check for idle client connections in case the current
8974b2
connection was still valid, but in doing so, it also stored the current
8974b2
time into the last_request_time field of the client context.
8974b2
8974b2
This kept the connection always alive, because the last_request_time
8974b2
could then never be older than the timeout.
8974b2
8974b2
This patch changes the setup_client_idle_timer() function to only do
8974b2
what the synopsis says and set the idle timer. The caller (usually the
8974b2
function that accepts the connection) is supposed to store the request
8974b2
time itself.
8974b2
8974b2
Resolves:
8974b2
https://pagure.io/SSSD/sssd/issue/3448
8974b2
8974b2
Reviewed-by: Lukáš Slebodník <lslebodn@redhat.com>
8974b2
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
8974b2
---
8974b2
 src/responder/common/responder_common.c | 16 +++++++++++-----
8974b2
 1 file changed, 11 insertions(+), 5 deletions(-)
8974b2
8974b2
diff --git a/src/responder/common/responder_common.c b/src/responder/common/responder_common.c
8974b2
index 9d4889be652c6d6fb974b59001a9ac77b496e9ab..9d706f9799ef1b31122d8380fbf9c53ba0cc9e68 100644
8974b2
--- a/src/responder/common/responder_common.c
8974b2
+++ b/src/responder/common/responder_common.c
8974b2
@@ -607,7 +607,15 @@ static void accept_fd_handler(struct tevent_context *ev,
8974b2
     cctx->ev = ev;
8974b2
     cctx->rctx = rctx;
8974b2
 
8974b2
-    /* Set up the idle timer */
8974b2
+    /* Record the new time and set up the idle timer */
8974b2
+    ret = reset_client_idle_timer(cctx);
8974b2
+    if (ret != EOK) {
8974b2
+        DEBUG(SSSDBG_MINOR_FAILURE,
8974b2
+              "Could not create idle timer for client. "
8974b2
+              "This connection may not auto-terminate\n");
8974b2
+        /* Non-fatal, continue */
8974b2
+    }
8974b2
+
8974b2
     ret = setup_client_idle_timer(cctx);
8974b2
     if (ret != EOK) {
8974b2
         DEBUG(SSSDBG_CRIT_FAILURE,
8974b2
@@ -634,7 +642,7 @@ static void client_idle_handler(struct tevent_context *ev,
8974b2
     if (cctx->last_request_time > now) {
8974b2
         DEBUG(SSSDBG_IMPORTANT_INFO,
8974b2
               "Time shift detected, re-scheduling the client timeout\n");
8974b2
-        goto end;
8974b2
+        goto done;
8974b2
     }
8974b2
 
8974b2
     if ((now - cctx->last_request_time) > cctx->rctx->client_idle_timeout) {
8974b2
@@ -648,7 +656,7 @@ static void client_idle_handler(struct tevent_context *ev,
8974b2
         return;
8974b2
     }
8974b2
 
8974b2
-end:
8974b2
+done:
8974b2
     setup_client_idle_timer(cctx);
8974b2
 }
8974b2
 
8974b2
@@ -661,11 +669,9 @@ errno_t reset_client_idle_timer(struct cli_ctx *cctx)
8974b2
 
8974b2
 static errno_t setup_client_idle_timer(struct cli_ctx *cctx)
8974b2
 {
8974b2
-    time_t now = time(NULL);
8974b2
     struct timeval tv =
8974b2
             tevent_timeval_current_ofs(cctx->rctx->client_idle_timeout/2, 0);
8974b2
 
8974b2
-    cctx->last_request_time = now;
8974b2
     talloc_zfree(cctx->idle);
8974b2
 
8974b2
     cctx->idle = tevent_add_timer(cctx->ev, cctx, tv, client_idle_handler, cctx);
8974b2
-- 
8974b2
2.9.4
8974b2