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:
@@ -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
|
||||||
|
|||||||
@@ -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."
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user