fix(cron): close lock_fd on failed flock to prevent fd leak

This commit is contained in:
alireza78a
2026-03-03 02:09:56 +03:30
parent e5f719a33b
commit ee541c84f1

View File

@@ -280,6 +280,7 @@ def tick(verbose: bool = True) -> int:
_LOCK_DIR.mkdir(parents=True, exist_ok=True)
# Cross-platform file locking: fcntl on Unix, msvcrt on Windows
lock_fd = None
try:
lock_fd = open(_LOCK_FILE, "w")
if fcntl:
@@ -288,6 +289,8 @@ def tick(verbose: bool = True) -> int:
msvcrt.locking(lock_fd.fileno(), msvcrt.LK_NBLCK, 1)
except (OSError, IOError):
logger.debug("Tick skipped — another instance holds the lock")
if lock_fd is not None:
lock_fd.close()
return 0
try: