From 7d1a937b9f4ca9913eb19d32e6b1c27583a37712 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 30 Jul 2026 22:50:13 +0200 Subject: [PATCH] fix(quickadapter): prevent best-params lock hang on FIFO paths (#191) Open the best-params lock with O_NONBLOCK so a pre-existing FIFO at .optuna-best-params.lock no longer blocks the O_RDONLY shared-load open until a writer appears (O_NOFOLLOW rejects symlinks but not FIFOs), hanging strategy startup before the S_ISREG guard can reject the non-regular file. The flag is inert on regular files and does not affect the subsequent blocking flock() (governed by LOCK_NB, not the fd flag). Addresses the unresolved P2 review thread on merged PR #185. --- quickadapter/user_data/strategies/Utils.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/quickadapter/user_data/strategies/Utils.py b/quickadapter/user_data/strategies/Utils.py index a306d18..b1b6fda 100644 --- a/quickadapter/user_data/strategies/Utils.py +++ b/quickadapter/user_data/strategies/Utils.py @@ -5448,12 +5448,15 @@ def _locked_optuna_best_params( ) -> Iterator[None]: """Serialize best-params I/O using a stable lock file.""" lock_path = best_params_path.parent / ".optuna-best-params.lock" + # O_NONBLOCK so a pre-existing FIFO (unlike a symlink, not caught by + # O_NOFOLLOW) cannot hang this open before the S_ISREG guard rejects it. lock_fd = os.open( lock_path, (os.O_RDWR if exclusive else os.O_RDONLY) | os.O_CREAT | os.O_CLOEXEC - | os.O_NOFOLLOW, + | os.O_NOFOLLOW + | os.O_NONBLOCK, 0o666, ) try: -- 2.53.0