mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-17 13:44:32 +01:00
Make gstack's shell locks hold when mkdir reports a race it lost (GST-2247) (#4262)
* Make gstack's shell locks hold when mkdir reports a race it lost (GST-2247) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * Fix lock tests and fixtures for gstack_lock_take; trim setup-gbrain lock prose Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * Ship the lock helper with every copied runtime and fixture that runs a lock The Claude Code wrapper's copied runtime now includes bin/gstack-lock.sh, and bin/gstack-render-claude.sh sources it beside itself, so gstack-config set works in a copied runtime and the render lock is taken by every caller. Test fixtures that copy single bin scripts now copy the helper too, and the mkdir lock guard is registered as a repo-wide docs reader. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * Release a lock whose owner file could not be fully written gstack_lock_take created the owner file with a noclobber redirect and, when that redirect failed, treated an existing file as a competing holder. If the file was created but the write then failed (disk full, quota, ulimit -f), the helper found its own empty file, returned 1 and left a lock nobody held; freeze's state lock has no stale recovery, so it stayed busy until removed by hand. The helper now tells "opened but write failed" from "already held", removes its own file and directory, and returns 3. The inline copy in gstack-ff-update is updated byte for byte, and a new test under ulimit -f 0 fails on the old helper. Review-Finding: s11/outside-voice#1 reader=outside-voice Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * Describe the lease lock as gstack_lock_take's O_EXCL owner file Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> --------- Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
76fad3edd9
commit
bcece3fbcd
50 files changed
+621
-154
No files matched your search
@@ -254,9 +254,11 @@ by rename, prune) and reclaim (reread, then delete only the record judged
|
||||
stale) run under one lock in the lease directory, a `.lock` directory whose
|
||||
`owner` file names its holder's pid and start identity, so a renewal is never
|
||||
deleted and a live lease never disappears from a concurrent scan. The lock is a
|
||||
directory because `mkdir` is atomic on every host, while Git Bash on Windows
|
||||
cannot `ln -s` to a target that does not exist (#3330). A taker publishes a
|
||||
claim before its `mkdir` and renames it in as the owner after, so an ownerless
|
||||
directory taken with `gstack_lock_take` (`bin/gstack-lock.sh`), which creates
|
||||
the `owner` file with O_EXCL, because `mkdir`'s exit status is no lock on
|
||||
Ubuntu 26.04's uutils `mkdir` and Git Bash on Windows cannot `ln -s` to a
|
||||
target that does not exist (#3330). A taker publishes a claim before its
|
||||
`mkdir` and removes it only after its owner file is written, so an ownerless
|
||||
lock is broken only once no claimant lives and the lock is at least 2 s old
|
||||
and unchanged while checked, which keeps a taker between its two steps safe.
|
||||
A claim that records no start identity is abandoned after 2 minutes, so a
|
||||
|
||||
@@ -1882,6 +1882,36 @@ A `tracked-by-project` or `version-reverted` cause has its own section:
|
||||
listed changes, check out the default branch, move local commits to another
|
||||
branch), then re-run `bin/gstack-upgrade`. A reinstall that failed after the
|
||||
fast-forward is completed by the next run (`reinstall pending from <version>`).
|
||||
For `another gstack updater holds <state root>/.setup-lock (pid <n>)`, wait
|
||||
for that update to finish. If no gstack update is running (`kill -0 <n>`
|
||||
fails, or the pid reads `unknown` because the holder was killed before it
|
||||
wrote one), remove the lock with `rm -rf <state root>/.setup-lock` and
|
||||
re-run. See [how gstack's shell locks work](#shell-locks).
|
||||
|
||||
<a id="shell-locks"></a>
|
||||
### Two gstack updates, setups or config writes ran at once (Ubuntu 26.04, uutils `mkdir`)
|
||||
|
||||
**Meaning.** gstack's shell locks (the updater's `.setup-lock`, the config
|
||||
lock `.config-yaml.lock`, the install registry, the developer profile,
|
||||
settings.json, the Chromium install, the brain-sync drain, freeze and the
|
||||
lease directory) are lock directories. Older gstack held one when
|
||||
`mkdir <lock>` succeeded. Rust coreutils (uutils) 0.8.0, the `mkdir` on
|
||||
Ubuntu 26.04 and on GitHub's `ubuntu-latest` from 2026-11-09, reports success
|
||||
even when another process created the directory first, so two racing callers
|
||||
could both hold the lock: two updates moving one checkout, or two
|
||||
`gstack-config set` calls where one write dropped the other's key. GNU and
|
||||
BSD `mkdir` never did this.
|
||||
|
||||
**Fix.** Upgrade gstack (`/gstack-upgrade`). Every lock is now taken by
|
||||
`gstack_lock_take` in `bin/gstack-lock.sh`: `mkdir` only makes the
|
||||
directory, and the holder is whoever creates its `pid` (or `owner`) file
|
||||
with the shell's noclobber redirect, which opens it `O_CREAT|O_EXCL`, so
|
||||
exactly one caller wins whatever `mkdir` reports. Waiting, stale-lock
|
||||
recovery and release are unchanged. A lock directory with no owner file
|
||||
inside, left by a process killed while taking it, still counts as held until
|
||||
the caller's own stale-lock rule clears it; when nothing is running, remove it
|
||||
with `rm -rf <lock>`. Re-set any config key you set during a concurrent write
|
||||
on 26.04 (`gstack-config get <key>` shows what stuck).
|
||||
|
||||
<a id="upgrade-busy"></a>
|
||||
### `gstack-upgrade: live gstack sessions hold this installation: pid <p> (<age>m), ...; nothing was changed; fix: ... (UPGRADE_BUSY)` / `gstack-upgrade: a shared harness (capy-server, pid <p>) holds a lease <n>m old; ... (UPGRADE_BUSY)`
|
||||
|
||||
Reference in new issue
Block a user