Repository navigation
Conversation
… annotate a lost lock Follow-up to #192, which merged before these review fixes were pushed: - A failed token write was swallowed (acquire is called as `|| exit 1`, where set -e does not apply), returning success and leaking an ownerless lock that every later run then waited 300 s for. A failed write now undoes the lock and fails the acquire. - The EXIT trap is installed before the lock is taken, so a signal between mkdir and the end of acquire cannot leave it behind (release is idempotent and does nothing without a token). - A lost or taken lock was only a plain stderr line inside a collapsed group of a job that exits 0, so nobody would see that serialization failed, nor the one clue to the real cause. On GitHub Actions it is now also a `::warning` annotation, and the text asks for the run to be reported. New tests fail against the code on main: failed write (no leak, and no spurious "held by another run" later), the annotation for both cases, no annotation off Actions, and the trap-before-acquire order. Human guided, AI implemented
|
No actionable comments were generated in the recent review. Summary
Change: Bug fix Merge Risk:
|
|
Claude finished @krassx's task in 41s —— View job Review of PR #193I read the diff alongside Overall risk: Low Merge recommendation: Merge. The one finding is a P3: a comment overclaims, and a rare race is only narrowed, not closed. FindingsP3 — The trap-before-acquire change does not close the mkdir→owner window (
Checked, no issues
Positives
|
| # behind. The release does nothing without a token and is idempotent, so this and the explicit one | ||
| # below can both run. | ||
| trap 'pack_lock_release; [[ -n "${PACK_INSTALL_DIR:-}" ]] || rm -rf "$WORK"' EXIT | ||
| pack_lock_acquire "${TMPDIR:-/tmp}/bugsee-pack-install.lock.d" 300 || exit 1 |
There was a problem hiding this comment.
Severity: P3 Low
Problem: Moving the trap before acquire does not close the window the comment describes. The leak window is between mkdir "$lock" succeeding and printf ... > "$lock/owner" completing, and the release in this trap cannot clean up in that window:
- If the signal lands before
PACK_LOCK_TOKENis assigned,pack_lock_releasereturns at its first line ([[ -n "$PACK_LOCK_TOKEN" ]] || return 0) and the lock stays. - If it lands after the token is set but before
owneris written, release reads an empty owner. That is not equal to the token, so it takes the "held by another run" branch and leaves the directory.
I checked the second case with mkdir lk; PACK_LOCK_DIR=lk; PACK_LOCK_TOKEN=1.2; pack_lock_release; ls -d lk. It prints "held by another run now; left it alone" (and the new ::warning annotation under Actions), and lk is still there.
Impact: A SIGTERM or SIGINT (job cancel, timeout) in that sub-millisecond window still leaves an ownerless lock. Every later run then waits 300 s and fails with "stale lock?", which is the failure the first fix in this PR addresses. The new annotation would blame "another run" for it.
Scenario: The window is tiny, so this is rare. The point is that the PR text and this comment claim it is closed, and the new test only checks the textual order of trap and pack_lock_acquire in the source. It never exercises the window.
Fix: Either:
- in
pack_lock_acquire, setPACK_LOCK_DIRandPACK_LOCK_TOKENbeforemkdir, and clear them ifmkdirfails; and inpack_lock_release, treat "owner empty and token set" as ours to remove only when we have just created the directory (for example, aPACK_LOCK_CREATED=1flag set right after a successfulmkdir); or - soften the comment and PR description to say this narrows the window rather than closing it.
Follow-up to #192, which merged before the review fixes on it were pushed. Main has the ownership-checked lock; these three review findings are not in it.
What
pack_lock_acquireis called as... || exit 1, whereset -edoes not apply, so a failingprintf > "$lock/owner"only printed an error and the function returned 0. The lock directory then stayed with no owner and every later run waited the full 300 s and failed with 'stale lock?'. A failed write now removes the partialownerand the lock directory, clears the state, printsFAIL: could not record the owner in <lock>and returns 1.mkdirand the end of acquire cannot leave the lock behind. Release is idempotent and does nothing without a token, so this is safe.::warning title=pack-install lock::...annotation (the runner parses it whenci-each-version.shprints the log), and the text says nothing in this repository removes the directory and asks for the run to be reported.Verified
Five new tests fail against the code on main and pass here: the failed write (no lock left, acquire returns 1, the lock can be taken again, and a later release does not claim 'held by another run';
printfis overridden to fail so it does not depend on file permissions, which root ignores), the annotation for both the lost and the taken case, no annotation off Actions, and the trap-before-acquire order.yarn lint,yarn typecheckandyarn jestpass (5,280 tests).Not verified
As in #192, what removes the lock directory on the hosted runner is still unknown. The annotation is there so that, if it recurs, the run summary says so.
Human guided, AI implemented