Blame SOURCES/0070-Ticket-48311-nunc-stans-Attempt-to-release-connectio.patch

246821
From d7609aa1166fb79dd5e1f838f5ab27e0924441a1 Mon Sep 17 00:00:00 2001
246821
From: William Brown <firstyear@redhat.com>
246821
Date: Fri, 6 Nov 2015 14:56:44 +1000
246821
Subject: [PATCH 70/75] Ticket 48311  -nunc-stans: Attempt to release
246821
 connection that is not acquired https://fedorahosted.org/389/ticket/48311
246821
246821
Bug Description: DS with nunc stans enabled produces lots of messages like
246821
[13/Oct/2015:11:29:24 -0400] connection - conn=98 fd=161 Attempt to release
246821
connection that is not acquired
246821
246821
FixDescription: From the original patch:
246821
 * Do not call connection_acquire_nolock() inside a PR_ASSERT call.
246821
 * Also changed other PR_ASSERTs to only be called if DEBUG is set
246821
246821
This additionally guarantees the return codes of these functions since we have
246821
removed the PR_ASSERT that previously wrapped these function calls. If these
246821
assertions fail, we log to the error log in all cases.
246821
246821
Author: wibrown
246821
246821
Review by: mreynolds, nhosoi (Thanks!)
246821
246821
(cherry picked from commit 49aaf98732d1e16dde3edb81272de8203aded21c)
246821
(cherry picked from commit b03987689c3a2477630e2a3452e64cc7759ba5f3)
246821
---
246821
 ldap/servers/slapd/daemon.c | 23 ++++++++++++++++++++---
246821
 1 file changed, 20 insertions(+), 3 deletions(-)
246821
246821
diff --git a/ldap/servers/slapd/daemon.c b/ldap/servers/slapd/daemon.c
246821
index 82099bc..bd3bfb2 100644
246821
--- a/ldap/servers/slapd/daemon.c
246821
+++ b/ldap/servers/slapd/daemon.c
246821
@@ -1839,7 +1839,12 @@ ns_handle_closure(struct ns_job_t *job)
246821
 #ifdef DEBUG
246821
 	PR_ASSERT(0 == NS_JOB_IS_THREAD(ns_job_get_type(job)));
246821
 #else
246821
-	NS_JOB_IS_THREAD(ns_job_get_type(job));
246821
+    /* This doesn't actually confirm it's in the event loop thread, but it's a start */
246821
+	if (NS_JOB_IS_THREAD(ns_job_get_type(job)) != 0) {
246821
+		LDAPDebug2Args(LDAP_DEBUG_ANY, "ns_handle_closure: Attempt to close outside of event loop thread %" NSPRIu64 " for fd=%d\n",
246821
+			c->c_connid, c->c_sd);
246821
+		return;
246821
+	}
246821
 #endif
246821
 	PR_Lock(c->c_mutex);
246821
 	connection_release_nolock_ext(c, 1); /* release ref acquired for event framework */
246821
@@ -1896,7 +1901,14 @@ ns_connection_post_io_or_closing(Connection *conn)
246821
 #ifdef DEBUG
246821
 		PR_ASSERT(0 == connection_acquire_nolock(conn));
246821
 #else
246821
-		connection_acquire_nolock(conn); /* event framework now has a reference */
246821
+		if (connection_acquire_nolock(conn) != 0) { /* event framework now has a reference */
246821
+			/* 
246821
+			 * This has already been logged as an error in ./ldap/servers/slapd/connection.c
246821
+			 * The error occurs when we get a connection in a closing state.
246821
+			 * For now we return, but there is probably a better way to handle the error case.
246821
+			 */
246821
+			return;
246821
+		}
246821
 #endif
246821
 		ns_add_io_timeout_job(conn->c_tp, conn->c_prfd, &tv,
246821
 				      NS_JOB_READ|NS_JOB_PRESERVE_FD,
246821
@@ -1922,7 +1934,12 @@ ns_handle_pr_read_ready(struct ns_job_t *job)
246821
 #ifdef DEBUG
246821
 	PR_ASSERT(0 == NS_JOB_IS_THREAD(ns_job_get_type(job)));
246821
 #else
246821
-	NS_JOB_IS_THREAD(ns_job_get_type(job));
246821
+    /* This doesn't actually confirm it's in the event loop thread, but it's a start */
246821
+	if (NS_JOB_IS_THREAD(ns_job_get_type(job)) != 0) {
246821
+		LDAPDebug2Args(LDAP_DEBUG_ANY, "ns_handle_pr_read_ready: Attempt to handle read ready outside of event loop thread %" NSPRIu64 " for fd=%d\n",
246821
+			c->c_connid, c->c_sd);
246821
+		return;
246821
+	}
246821
 #endif
246821
 
246821
 	PR_Lock(c->c_mutex);
246821
-- 
246821
2.4.3
246821