From 3671e6859a92f58764ee9d42e80ce7e4ee671b0f Mon Sep 17 00:00:00 2001 From: ImMin5 Date: Mon, 19 May 2025 11:30:13 +0900 Subject: [PATCH 1/2] feat: add thread-safe handler initialization using double-checked locking Signed-off-by: ImMin5 --- src/spaceone/core/handler/__init__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/spaceone/core/handler/__init__.py b/src/spaceone/core/handler/__init__.py index d45e92f..fcc0ac1 100644 --- a/src/spaceone/core/handler/__init__.py +++ b/src/spaceone/core/handler/__init__.py @@ -1,5 +1,6 @@ import abc import logging +import threading from typing import List from spaceone.core.base import CoreObject from spaceone.core import config @@ -25,6 +26,7 @@ "mutation": [], "event": [], } +_HANDLER_THREAD_LOCK = threading.Lock() _LOGGER = logging.getLogger(__name__) @@ -145,5 +147,7 @@ def get_event_handlers() -> List[BaseEventHandler]: def _check_init_state() -> None: if not _HANDLER_INFO["init"]: - _init_handlers() - _HANDLER_INFO["init"] = True + with _HANDLER_THREAD_LOCK: + if not _HANDLER_INFO["init"]: + _init_handlers() + _HANDLER_INFO["init"] = True From 118fbb30e56cc098004008870061939c21ffd3ab Mon Sep 17 00:00:00 2001 From: ImMin5 Date: Mon, 19 May 2025 11:41:16 +0900 Subject: [PATCH 2/2] fix: rename thread lock variable for clarity in handler initialization Signed-off-by: ImMin5 --- src/spaceone/core/handler/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/spaceone/core/handler/__init__.py b/src/spaceone/core/handler/__init__.py index fcc0ac1..713ab1f 100644 --- a/src/spaceone/core/handler/__init__.py +++ b/src/spaceone/core/handler/__init__.py @@ -26,7 +26,7 @@ "mutation": [], "event": [], } -_HANDLER_THREAD_LOCK = threading.Lock() +_HANDLER_INIT_LOCK = threading.Lock() _LOGGER = logging.getLogger(__name__) @@ -147,7 +147,7 @@ def get_event_handlers() -> List[BaseEventHandler]: def _check_init_state() -> None: if not _HANDLER_INFO["init"]: - with _HANDLER_THREAD_LOCK: + with _HANDLER_INIT_LOCK: if not _HANDLER_INFO["init"]: _init_handlers() _HANDLER_INFO["init"] = True