From be13705f5cc256f22e06ca27d1a762e510df718b Mon Sep 17 00:00:00 2001 From: annguyenNous Date: Sat, 30 May 2026 14:11:57 +0700 Subject: [PATCH] fix: guard flock(LOCK_UN) against OSError in kanban_db and google_oauth MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two files had unguarded fcntl.flock(LOCK_UN) calls in finally blocks that could raise OSError and propagate as unhandled exceptions. - hermes_cli/kanban_db.py: flock(LOCK_UN) in finally block without try/except — if unlock fails, the exception propagates even though handle.close() still runs in the outer finally. - agent/google_oauth.py: flock(LOCK_UN) inside try/except ImportError (for msvcrt fallback) but OSError was not caught. The msvcrt path already had proper OSError guarding, but the fcntl path did not. Both fixes follow the existing pattern used in tools/skill_usage.py, tools/memory_tool.py, and hermes_cli/auth.py where flock(LOCK_UN) is already wrapped in try/except (OSError, IOError): pass. --- agent/google_oauth.py | 2 +- hermes_cli/kanban_db.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/agent/google_oauth.py b/agent/google_oauth.py index 9eb55ec19dc31..8ea585a83c4c0 100644 --- a/agent/google_oauth.py +++ b/agent/google_oauth.py @@ -227,7 +227,7 @@ def _credentials_lock(timeout_seconds: float = LOCK_TIMEOUT_SECONDS): import fcntl fcntl.flock(fd, fcntl.LOCK_UN) - except ImportError: + except (ImportError, OSError): try: import msvcrt # type: ignore[import-not-found] diff --git a/hermes_cli/kanban_db.py b/hermes_cli/kanban_db.py index 5e465e87a6f1d..c070bcad64559 100644 --- a/hermes_cli/kanban_db.py +++ b/hermes_cli/kanban_db.py @@ -1072,7 +1072,10 @@ def _cross_process_init_lock(path: Path): else: import fcntl - fcntl.flock(handle.fileno(), fcntl.LOCK_UN) + try: + fcntl.flock(handle.fileno(), fcntl.LOCK_UN) + except OSError: + pass finally: handle.close()