fix(cron): close lock_fd on failed flock to prevent fd leak
This commit is contained in:
parent
e5f719a33b
commit
ee541c84f1
1 changed files with 3 additions and 0 deletions
|
|
@ -280,6 +280,7 @@ def tick(verbose: bool = True) -> int:
|
||||||
_LOCK_DIR.mkdir(parents=True, exist_ok=True)
|
_LOCK_DIR.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
# Cross-platform file locking: fcntl on Unix, msvcrt on Windows
|
# Cross-platform file locking: fcntl on Unix, msvcrt on Windows
|
||||||
|
lock_fd = None
|
||||||
try:
|
try:
|
||||||
lock_fd = open(_LOCK_FILE, "w")
|
lock_fd = open(_LOCK_FILE, "w")
|
||||||
if fcntl:
|
if fcntl:
|
||||||
|
|
@ -288,6 +289,8 @@ def tick(verbose: bool = True) -> int:
|
||||||
msvcrt.locking(lock_fd.fileno(), msvcrt.LK_NBLCK, 1)
|
msvcrt.locking(lock_fd.fileno(), msvcrt.LK_NBLCK, 1)
|
||||||
except (OSError, IOError):
|
except (OSError, IOError):
|
||||||
logger.debug("Tick skipped — another instance holds the lock")
|
logger.debug("Tick skipped — another instance holds the lock")
|
||||||
|
if lock_fd is not None:
|
||||||
|
lock_fd.close()
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue