mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-17 21:54:30 +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
+8
-6
@@ -552,18 +552,21 @@ read_config_value() {
|
||||
|
||||
# ── Config writes: one lock, one read-modify-write rename ──────────────────
|
||||
# Every mutation of config.yaml (set, unset, the transcript_repos pair, the
|
||||
# user-slug writer) holds an atomic mkdir lock and replaces the file with one
|
||||
# user-slug writer) holds one lock directory and replaces the file with one
|
||||
# rename, so concurrent writers never lose each other's keys and an
|
||||
# interrupted write leaves the old file. The pid file holds "<pid> <epoch>";
|
||||
# a lock whose holder is dead or older than 10 s is taken over. No flock(1):
|
||||
# stock macOS does not ship it.
|
||||
# interrupted write leaves the old file. The lock is taken with
|
||||
# gstack_lock_take (bin/gstack-lock.sh), which creates the pid file with
|
||||
# O_EXCL because mkdir's exit status is not a lock on Ubuntu 26.04's uutils
|
||||
# mkdir. The pid file holds "<pid> <epoch>"; a lock whose holder is dead or
|
||||
# older than 10 s is taken over. No flock(1): stock macOS does not ship it.
|
||||
CONFIG_LOCK="$STATE_DIR/.config-yaml.lock"
|
||||
_config_locked=""
|
||||
|
||||
config_lock() {
|
||||
mkdir -p "$STATE_DIR"
|
||||
. "$(dirname "$0")/gstack-lock.sh" 2>/dev/null || { echo "Error: $(dirname "$0")/gstack-lock.sh is missing. Existing value left unchanged. fix: reinstall with ./setup or /gstack-upgrade" >&2; exit 1; }
|
||||
local waited=0 held pid ts stale
|
||||
while ! mkdir "$CONFIG_LOCK" 2>/dev/null; do
|
||||
while ! gstack_lock_take "$CONFIG_LOCK" pid "$$ $(date +%s)"; do
|
||||
if [ ! -w "$STATE_DIR" ]; then
|
||||
echo "Error: cannot write to $STATE_DIR (its config lock could not be created). Existing value left unchanged." >&2
|
||||
exit 1
|
||||
@@ -589,7 +592,6 @@ config_lock() {
|
||||
fi
|
||||
sleep 0.05
|
||||
done
|
||||
printf '%s %s\n' "$$" "$(date +%s)" > "$CONFIG_LOCK/pid"
|
||||
_config_locked=1
|
||||
trap 'config_unlock' EXIT
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user