From af1013fc1d5f35cb945042eb8a1cd2acde3fd144 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 18 Nov 2025 23:27:31 +0000 Subject: [PATCH] Fix deadlock by using RLock instead of Lock - Replace threading.Lock() with threading.RLock() (reentrant lock) - Prevents deadlock when _initialize_chunker/_initialize_code_chunker call _initialize_embedding_model while holding the lock - RLock allows same thread to re-acquire lock safely Addresses critical PR #17 review feedback --- surfsense_backend/app/config/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/surfsense_backend/app/config/__init__.py b/surfsense_backend/app/config/__init__.py index 922f453e5..127d08b94 100644 --- a/surfsense_backend/app/config/__init__.py +++ b/surfsense_backend/app/config/__init__.py @@ -184,7 +184,7 @@ class Config: _chunker_instance = None _code_chunker_instance = None _reranker_instance = None - _init_lock = threading.Lock() # Thread-safety lock for lazy initialization + _init_lock = threading.RLock() # Reentrant lock for nested initialization calls @classmethod def _initialize_embedding_model(cls):