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

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