Blame SOURCES/0024-Ticket-50370-CleanAllRUV-task-crashing-during-server.patch

26521d
From 5bed4704f3fa6fc6fca1cad9f132985cc7f68056 Mon Sep 17 00:00:00 2001
26521d
From: Mark Reynolds <mreynolds@redhat.com>
26521d
Date: Tue, 14 May 2019 13:58:42 -0400
26521d
Subject: [PATCH] Ticket 50370 -  CleanAllRUV task crashing during server
26521d
 shutdown
26521d
26521d
Description:  There is a race condition during server shutdown that
26521d
              can cause the server to crash.  Increment the active
26521d
              thread count for each cleaning task to prevent the plugins
26521d
              from being closed before the thread terminates.
26521d
26521d
https://pagure.io/389-ds-base/issue/50370
26521d
26521d
Reviewed by: firstyear(Thanks!)
26521d
26521d
(cherry picked from commit 7141b8d10382e8dcb8528b57e5226c82506b79b9)
26521d
---
26521d
 .../plugins/replication/repl5_replica_config.c     | 14 ++++++++++++--
26521d
 1 file changed, 12 insertions(+), 2 deletions(-)
26521d
26521d
diff --git a/ldap/servers/plugins/replication/repl5_replica_config.c b/ldap/servers/plugins/replication/repl5_replica_config.c
26521d
index a952b687d..b4aff9eb4 100644
26521d
--- a/ldap/servers/plugins/replication/repl5_replica_config.c
26521d
+++ b/ldap/servers/plugins/replication/repl5_replica_config.c
26521d
@@ -1630,9 +1630,13 @@ replica_cleanallruv_thread(void *arg)
26521d
     int aborted = 0;
26521d
     int rc = 0;
26521d
 
26521d
-    if (!data) {
26521d
+    if (!data || slapi_is_shutting_down()) {
26521d
         return; /* no data */
26521d
     }
26521d
+
26521d
+    /* Increase active thread count to prevent a race condition at server shutdown */
26521d
+    g_incr_active_threadcnt();
26521d
+
26521d
     if (data->task) {
26521d
         slapi_task_inc_refcount(data->task);
26521d
         slapi_log_err(SLAPI_LOG_PLUGIN, repl_plugin_name,
26521d
@@ -1912,6 +1916,7 @@ done:
26521d
     slapi_ch_free_string(&data->force);
26521d
     slapi_ch_free_string(&rid_text);
26521d
     slapi_ch_free((void **)&data);
26521d
+    g_decr_active_threadcnt();
26521d
 }
26521d
 
26521d
 /*
26521d
@@ -3005,9 +3010,13 @@ replica_abort_task_thread(void *arg)
26521d
     int release_it = 0;
26521d
     int count = 0, rc = 0;
26521d
 
26521d
-    if (!data) {
26521d
+    if (!data || slapi_is_shutting_down()) {
26521d
         return; /* no data */
26521d
     }
26521d
+
26521d
+    /* Increase active thread count to prevent a race condition at server shutdown */
26521d
+    g_incr_active_threadcnt();
26521d
+
26521d
     if (data->task) {
26521d
         slapi_task_inc_refcount(data->task);
26521d
         slapi_log_err(SLAPI_LOG_PLUGIN, repl_plugin_name, "replica_abort_task_thread --> refcount incremented.\n");
26521d
@@ -3134,6 +3143,7 @@ done:
26521d
     slapi_ch_free_string(&data->certify);
26521d
     slapi_sdn_free(&data->sdn);
26521d
     slapi_ch_free((void **)&data);
26521d
+    g_decr_active_threadcnt();
26521d
 }
26521d
 
26521d
 static int
26521d
-- 
26521d
2.17.2
26521d