Repository navigation
gpu_lock: a job's leftover background processes must not hold the lock - #90
Conversation
flock passed the locked fd to the command, so any background process a job left behind kept the GPU lock. On 2026-10-01 a hold that queued its successor from inside itself deadlocked the queue: the successor inherited the lock while waiting for older tickets that were waiting for that lock. flock -o closes the fd for the command, so the lock lasts exactly as long as the command. Tests cover both modes and fail without the change.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1913661a4f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| flock -x -w "$WAIT" -E 75 "$LOCK_FILE" "$@" | ||
| # -o: the lock is held by flock itself for the command's lifetime and is not inherited, so a | ||
| # background process the job leaves behind (or a successor ticket it queues) cannot keep it. | ||
| flock -o -x -w "$WAIT" -E 75 "$LOCK_FILE" "$@" |
There was a problem hiding this comment.
Reconcile
-o with the background-server contract
When a wrapped command deliberately starts a server in the background and then exits, this releases the lock while that server is still using the GPU, allowing a subsequent exclusive benchmark to run concurrently. This contradicts the same script's documented contract at lines 20–21 that a server left running keeps the GPU locked; flock --help confirms that -o will “close file descriptor before running command,” so descendants cannot retain it. Either revise that supported workflow and its callers or preserve the lock for legitimate background servers while addressing the successor deadlock separately.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 1c4f7a8. The header now says flock holds the lock for exactly the command's lifetime: children don't inherit it, so a job must stop its servers and background processes before it exits, and killing the flock process releases the lock. A shared-mode test is added.
|
Verdict: REQUEST CHANGES Reviewed head 1913661, one commit on main 85004ec. The fix is right; one documentation item blocks. What I checked.
BlockingB1. The documented lock contract contradicts the new behaviour. This is also Codex's P2 on
With Suggestions
Deployment, as the PR says: |
…the shared path Addresses review of #90 (and Codex's P2): the header no longer says a server left running keeps the GPU locked; jobs must stop their servers before they exit. Adds a shared-mode test: the lock is held, a second shared holder gets in, and the ticket is dropped.
|
@codex review |
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Verdict: APPROVE Re-reviewed 1c4f7a8.
Suggestion (not blocking): the reflowed line still says "GPU_LOCK_WAIT (seconds, default 4 h)", but the script sets Deployment: |
scripts/gpu_lock.shran its command with the locked file descriptor inherited, so any background process the job left behind kept the GPU lock.On 2026-10-01 at 06:17 this deadlocked the queue. A hold queued its successor with
setsid nohup gpu_lock.sh ... &from inside itself. The successor inherited fd 3, so it held the exclusive lock while it waited for older tickets, and those tickets were waiting for that same lock. The GPU sat idle with two priority holds blocked until the leftover processes were killed.The fix is
flock -oin both modes. flock now holds the lock for exactly the command's lifetime and closes the fd before running it, the same waygpu_startup_lock.shalready does.tests/test_gpu_lock.pycovers it:-xand-s);Both leftover-process tests fail on the old script and pass with the fix.
Deployment: merge, then
git pullin each checkout. git replaces the file, so running holders keep the old inode. Never edit the script in place.