refactor(gateway): drop the redundant writer lock

Both callers of _get_runtime_status_writer() already hold
_runtime_status_state_lock (an RLock); the flush paths read the module
attribute directly and never initialise. A second lock plus double-checked
init protected nothing, so the getter serialises on the state lock instead.
This commit is contained in:
kshitijk4poor
2026-09-20 18:01:37 +05:30
committed by kshitij
parent 97b2991537
commit f78148c7b9

View File

@@ -159,15 +159,13 @@ def _merge_over_on_disk(path: Path, payload: dict[str, Any]) -> dict[str, Any]:
return {**existing, **payload} if isinstance(existing, dict) else payload
_runtime_status_writer_lock = threading.Lock()
_runtime_status_writer: Optional[_RuntimeStatusWriter] = None
def _get_runtime_status_writer() -> _RuntimeStatusWriter:
"""Lazily create the single writer; callers serialise on ``_runtime_status_state_lock``."""
global _runtime_status_writer
if _runtime_status_writer is not None:
return _runtime_status_writer
with _runtime_status_writer_lock:
with _runtime_status_state_lock:
if _runtime_status_writer is None:
_runtime_status_writer = _RuntimeStatusWriter()
return _runtime_status_writer