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