From f78148c7b92aeeea0e30f6d2430a9248c6eb2f31 Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Sun, 20 Sep 2026 18:01:37 +0530 Subject: [PATCH] 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. --- gateway/status.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/gateway/status.py b/gateway/status.py index 32fe6fa2e8..cb646922c9 100644 --- a/gateway/status.py +++ b/gateway/status.py @@ -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