14f8ab
From 10f1730073b9fb02d2ed7f7de855afd6df0e5202 Mon Sep 17 00:00:00 2001
14f8ab
From: Xavi Hernandez <xhernandez@redhat.com>
14f8ab
Date: Wed, 19 Feb 2020 12:24:15 +0100
14f8ab
Subject: [PATCH 355/355] core: Prevent crash on process termination
14f8ab
14f8ab
A previous patch (ce61da816a) has fixed a use-after-free issue,
14f8ab
but it doesn't work well when the final cleanup is done at process
14f8ab
termination because gluster doesn't stop other threads before
14f8ab
calling exit().
14f8ab
14f8ab
For this reason, the final cleanup is removed to avoid the crash,
14f8ab
at least until the termination sequence properly stops all gluster
14f8ab
threads before exiting the program.
14f8ab
14f8ab
Upstream patch:
14f8ab
> Upstream patch link: https://review.gluster.org/c/glusterfs/+/24138
14f8ab
> Change-Id: Id7cfb4407fcf208e28f03a7c3cdc3ef9c1f3bf9b
14f8ab
> Fixes: bz#1801684
14f8ab
> Signed-off-by: Xavi Hernandez <xhernandez@redhat.com>
14f8ab
14f8ab
Change-Id: Id7cfb4407fcf208e28f03a7c3cdc3ef9c1f3bf9b
14f8ab
BUG: 1800703
14f8ab
Signed-off-by: Xavi Hernandez <xhernandez@redhat.com>
14f8ab
Reviewed-on: https://code.engineering.redhat.com/gerrit/192344
14f8ab
Tested-by: RHGS Build Bot <nigelb@redhat.com>
14f8ab
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
14f8ab
---
14f8ab
 libglusterfs/src/mem-pool.c | 30 +++++++++++-------------------
14f8ab
 1 file changed, 11 insertions(+), 19 deletions(-)
14f8ab
14f8ab
diff --git a/libglusterfs/src/mem-pool.c b/libglusterfs/src/mem-pool.c
14f8ab
index 2b41c01..73503e0 100644
14f8ab
--- a/libglusterfs/src/mem-pool.c
14f8ab
+++ b/libglusterfs/src/mem-pool.c
14f8ab
@@ -541,25 +541,17 @@ mem_pools_preinit(void)
14f8ab
 static __attribute__((destructor)) void
14f8ab
 mem_pools_postfini(void)
14f8ab
 {
14f8ab
-    per_thread_pool_list_t *pool_list, *next;
14f8ab
-
14f8ab
-    /* This is part of a process shutdown (or dlclose()) which means that
14f8ab
-     * most probably all threads should be stopped. However this is not the
14f8ab
-     * case for gluster and there are even legitimate situations in which we
14f8ab
-     * could have some threads alive. What is sure is that none of those
14f8ab
-     * threads should be using anything from this library, so destroying
14f8ab
-     * everything here should be fine and safe. */
14f8ab
-
14f8ab
-    list_for_each_entry_safe(pool_list, next, &pool_threads, thr_list)
14f8ab
-    {
14f8ab
-        mem_pool_thread_destructor(pool_list);
14f8ab
-    }
14f8ab
-
14f8ab
-    list_for_each_entry_safe(pool_list, next, &pool_free_threads, thr_list)
14f8ab
-    {
14f8ab
-        list_del(&pool_list->thr_list);
14f8ab
-        FREE(pool_list);
14f8ab
-    }
14f8ab
+    /* TODO: This function should destroy all per thread memory pools that
14f8ab
+     *       are still alive, but this is not possible right now because glibc
14f8ab
+     *       starts calling destructors as soon as exit() is called, and
14f8ab
+     *       gluster doesn't ensure that all threads have been stopped before
14f8ab
+     *       calling exit(). Existing threads would crash when they try to use
14f8ab
+     *       memory or they terminate if we destroy things here.
14f8ab
+     *
14f8ab
+     *       When we propertly terminate all threads, we can add the needed
14f8ab
+     *       code here. Till then we need to leave the memory allocated. Most
14f8ab
+     *       probably this function will be executed on process termination,
14f8ab
+     *       so the memory will be released anyway by the system. */
14f8ab
 }
14f8ab
 
14f8ab
 /* Call mem_pools_init() once threading has been configured completely. This
14f8ab
-- 
14f8ab
1.8.3.1
14f8ab