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

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