Repository navigation
Bound task-state lock acquisition #1652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
| import re | ||
| import stat | ||
| import subprocess | ||
| import time | ||
| from collections.abc import Iterator | ||
| from contextlib import contextmanager, suppress | ||
| from pathlib import Path | ||
|
|
@@ -111,7 +112,15 @@ def _local_state_directory(wt: Path, *, create: bool = False, lock: bool = False | |
| raise WorktreeError(f"local state directory is not a directory or is a symbolic link: {path}") from exc | ||
| try: | ||
| if lock: | ||
| fcntl.flock(fd, fcntl.LOCK_EX) | ||
| deadline = time.monotonic() + 60 | ||
| while (remaining := deadline - time.monotonic()) > 0: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Lock retry loop duplicates the poll-until-deadline pattern This adds another hand-written loop that waits with |
||
| try: | ||
| fcntl.flock(fd, fcntl.LOCK_EX | fcntl.LOCK_NB) | ||
| break | ||
| except BlockingIOError: | ||
| time.sleep(min(0.1, remaining)) | ||
| else: | ||
| raise TimeoutError(f"task state is busy in {wt}; retry when the other command finishes") | ||
| yield fd | ||
| finally: | ||
| os.close(fd) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Lock budget is a bare 60 instead of a named operation budget
The task says the lock should reuse the existing 60-second operation budget. Before the merge, the code tied it to
cli.GIT_TIMEOUT. Now_local_state_directoryhardcodes60, and the test asserts the literalnow == 60. Ifcli.GIT_TIMEOUT(orsandbox.GIT_TIMEOUT) changes, the lock budget will silently stop matching it.worktreecannot importcli, so the smallest fix is a module constant such asLOCK_TIMEOUT = 60.0inworktree.py, used in both the loop and the test (now == cli.worktree.LOCK_TIMEOUT).