Merge pull request #887 from MemPalace/fix/kg-close-lock

fix: add lock to KG close() — last missing lock (closes #883)
This commit is contained in:
Igor Lins e Silva
2026-04-14 17:24:36 -03:00
committed by GitHub
2 changed files with 17 additions and 3 deletions
+1
View File
@@ -99,6 +99,7 @@ class KnowledgeGraph:
def close(self): def close(self):
"""Close the database connection.""" """Close the database connection."""
with self._lock:
if self._connection is not None: if self._connection is not None:
self._connection.close() self._connection.close()
self._connection = None self._connection = None
+13
View File
@@ -0,0 +1,13 @@
"""TDD: KnowledgeGraph.close() must hold self._lock."""
import inspect
from mempalace.knowledge_graph import KnowledgeGraph
class TestKGCloseLock:
def test_close_holds_lock(self):
src = inspect.getsource(KnowledgeGraph.close)
assert "self._lock" in src, (
"close() does not acquire self._lock. "
"Closing while a read/write is in progress can corrupt data."
)