]> Piment Noir Git Repositories - freqai-strategies.git/commitdiff
fix(quickadapter): prevent best-params lock hang on FIFO paths (#191)
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Thu, 30 Jul 2026 20:50:13 +0000 (22:50 +0200)
committerGitHub <noreply@github.com>
Thu, 30 Jul 2026 20:50:13 +0000 (22:50 +0200)
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

index a306d18e496c65b70525c3ca1d396ad58ad2c03c..b1b6fda33d0ec2f27541ac83c78c4b1ccced07f3 100644 (file)
@@ -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: