From b6546f923b3bb918b71456fcc7394a81e8fc86e7 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Tue, 8 Mar 2016 11:30:27 -0500 Subject: [PATCH] Fix security key initialization race condition When initializing security key, a background thread may occur. Sometimes, the system would go to daemonize while that thread was still running, and the whole system could exit. Leading to incomplete write to globals as well as leaving the daemon looking at the data copied over from pre-fork and seeing the last state of that thread forever frozen. Make sure the background threads are fully done prior to exiting. --- confluent_server/confluent/config/configmanager.py | 6 +++++- confluent_server/confluent/main.py | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/confluent_server/confluent/config/configmanager.py b/confluent_server/confluent/config/configmanager.py index d241df9d..78f0e1c0 100644 --- a/confluent_server/confluent/config/configmanager.py +++ b/confluent_server/confluent/config/configmanager.py @@ -1238,10 +1238,14 @@ class ConfigManager(object): pass @classmethod - def shutdown(cls): + def wait_for_sync(cls): cls._bg_sync_to_file() if cls._cfgwriter is not None: cls._cfgwriter.join() + + @classmethod + def shutdown(cls): + cls.wait_for_sync() sys.exit(0) @classmethod diff --git a/confluent_server/confluent/main.py b/confluent_server/confluent/main.py index 98c6655e..306aac4e 100644 --- a/confluent_server/confluent/main.py +++ b/confluent_server/confluent/main.py @@ -145,6 +145,9 @@ def _initsecurity(config): with open(keyfile, 'r') as keyhandle: key = keyhandle.read() configmanager.init_masterkey(key) + # We don't want to os._exit() until sync finishes from + # init above + configmanager.ConfigManager.wait_for_sync() def run():