andykimpe / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 months ago
Clone

Blame SOURCES/0004-Ticket-49171-Nunc-Stans-incorrectly-reports-a-timeou.patch

74ca47
From 645e628626f4a3d4b662c067584b4efc6b5c70c5 Mon Sep 17 00:00:00 2001
74ca47
From: William Brown <firstyear@redhat.com>
74ca47
Date: Wed, 15 Mar 2017 10:46:38 +1000
74ca47
Subject: [PATCH 5/5] Ticket 49171 - Nunc Stans incorrectly reports a timeout
74ca47
74ca47
Bug Description:  In some cases nunc-stans would incorrectly report
74ca47
and IO timeout.
74ca47
74ca47
Fix Description:  Make the io output type volatile to prevent re-arranging
74ca47
of the code. We then make timeout exclusive to read, write and signal.
74ca47
Finally, we add an extra check into ns_handle_pr_read_ready that
74ca47
asserts we truly have an idle timeout. It issues a warning now
74ca47
instead if this scenario occurs, rather than closing the
74ca47
connection.
74ca47
74ca47
https://pagure.io/389-ds-base/issue/49171
74ca47
74ca47
Author: wibrown
74ca47
74ca47
Review by: mreynolds (thanks!)
74ca47
74ca47
(cherry picked from commit c8ce1b32cc365174c8280111c2d55bba45f7949f)
74ca47
---
74ca47
 ldap/servers/slapd/daemon.c           | 15 +++++++++++----
74ca47
 src/nunc-stans/ns/ns_event_fw_event.c | 28 ++++++++++++++++------------
74ca47
 2 files changed, 27 insertions(+), 16 deletions(-)
74ca47
74ca47
diff --git a/ldap/servers/slapd/daemon.c b/ldap/servers/slapd/daemon.c
74ca47
index a37c8c6..6b3331d 100644
74ca47
--- a/ldap/servers/slapd/daemon.c
74ca47
+++ b/ldap/servers/slapd/daemon.c
74ca47
@@ -1970,11 +1970,18 @@ ns_handle_pr_read_ready(struct ns_job_t *job)
74ca47
 	connection_release_nolock_ext(c, 1); /* release ref acquired when job was added */
74ca47
 	if (CONN_NEEDS_CLOSING(c)) {
74ca47
 		ns_handle_closure_nomutex(c);
74ca47
+		/* We shouldn't need the c_idletimeout check here because of how libevent works.
74ca47
+		 * consider testing this and removing it oneday.
74ca47
+		 */
74ca47
 	} else if (NS_JOB_IS_TIMER(ns_job_get_output_type(job))) {
74ca47
-		/* idle timeout */
74ca47
-		disconnect_server_nomutex_ext(c, c->c_connid, -1,
74ca47
-					      SLAPD_DISCONNECT_IDLE_TIMEOUT, EAGAIN,
74ca47
-				              0 /* do not schedule closure, do it next */);
74ca47
+		if (c->c_idletimeout > 0) {
74ca47
+			/* idle timeout */
74ca47
+			disconnect_server_nomutex_ext(c, c->c_connid, -1,
74ca47
+							  SLAPD_DISCONNECT_IDLE_TIMEOUT, EAGAIN,
74ca47
+								  0 /* do not schedule closure, do it next */);
74ca47
+		} else {
74ca47
+			slapi_log_err(SLAPI_LOG_WARNING, "ns_handle_pr_read_ready", "Received idletime out with c->c_idletimeout as 0. Ignoring.\n");
74ca47
+		}
74ca47
 		ns_handle_closure_nomutex(c);
74ca47
 	} else if ((connection_activity(c, maxthreads)) == -1) {
74ca47
 		/* This might happen as a result of
74ca47
diff --git a/src/nunc-stans/ns/ns_event_fw_event.c b/src/nunc-stans/ns/ns_event_fw_event.c
74ca47
index 58dac28..3acbaf7 100644
74ca47
--- a/src/nunc-stans/ns/ns_event_fw_event.c
74ca47
+++ b/src/nunc-stans/ns/ns_event_fw_event.c
74ca47
@@ -71,18 +71,22 @@ event_logger_cb(int severity, const char *msg)
74ca47
 static ns_job_type_t
74ca47
 event_flags_to_type(short events)
74ca47
 {
74ca47
-    ns_job_type_t job_type = 0;
74ca47
-    if (events & EV_READ) {
74ca47
-        job_type |= NS_JOB_READ;
74ca47
-    }
74ca47
-    if (events & EV_WRITE) {
74ca47
-        job_type |= NS_JOB_WRITE;
74ca47
-    }
74ca47
-    if (events & EV_TIMEOUT) {
74ca47
-        job_type |= NS_JOB_TIMER;
74ca47
-    }
74ca47
-    if (events & EV_SIGNAL) {
74ca47
-        job_type |= NS_JOB_SIGNAL;
74ca47
+    /* The volatile here prevents gcc rearranging this code within the thread. */
74ca47
+    volatile ns_job_type_t job_type = 0;
74ca47
+
74ca47
+    /* Either we timeout *or* we are a real event */
74ca47
+    if (!(events & EV_TIMEOUT)) {
74ca47
+        if (events & EV_READ) {
74ca47
+            job_type |= NS_JOB_READ;
74ca47
+        }
74ca47
+        if (events & EV_WRITE) {
74ca47
+            job_type |= NS_JOB_WRITE;
74ca47
+        }
74ca47
+        if (events & EV_SIGNAL) {
74ca47
+            job_type |= NS_JOB_SIGNAL;
74ca47
+        }
74ca47
+    } else {
74ca47
+        job_type = NS_JOB_TIMER;
74ca47
     }
74ca47
     return job_type;
74ca47
 }
74ca47
-- 
74ca47
2.9.3
74ca47