Skip to content

fix: read the lock age with GNU stat first so Linux appends do not die - #2

Merged
jeanfbrito merged 2 commits into
mainfrom
fix/ledger-append-linux-stat
Oct 10, 2026
Merged

jeanfbrito merged 2 commits into
mainfrom
fix/ledger-append-linux-stat

Conversation

@jeanfbrito

Copy link
Copy Markdown
Owner

Problem

CI on main has failed since 2026-10-06 on the ledger-append.sh concurrency check. The log shows line 88: File: unbound variable.

Cause

The stale-lock sweep ran stat -f %m "$LOCK_DIR" || stat -c %Y "$LOCK_DIR". On Linux, stat -f means filesystem status: it exits 0 and prints text. The text went into the age arithmetic, which failed under set -u, and the writer exited before it appended. macOS was not affected.

On Linux this meant:

  • Entries were lost when writers collided: 17 of 20 landed in an Ubuntu 24.04 container.
  • A lock left by a crashed writer blocked every later append.

What changed

  • scripts/ledger-append.sh: runs stat -c %Y first. BSD stat rejects -c, so macOS falls through to stat -f %m. A value that is not a number is ignored.
  • verify.sh: a new check leaves a lock dir dated 2020. It expects the sweep to remove it at once and the entry to land with no timeout marker.

Verification

  • 20 parallel appends gave 20 of 20 entries on 3 runs each, in Ubuntu 24.04 and on macOS.
  • The full verify.sh passes on macOS and in Ubuntu 24.04 with git installed.
  • With the old script in Ubuntu, both the concurrency check and the new stale-lock check fail.

The stale-lock sweep in ledger-append.sh ran `stat -f %m || stat -c %Y`.
On Linux, `stat -f` is filesystem status: it exits 0 and prints text, so
the age arithmetic failed under `set -u` and the writer exited before it
appended. Under contention, entries were lost (17 of 20 in an Ubuntu
container), and a stale lock blocked every append.

Run `stat -c %Y` first. BSD stat rejects `-c`, so macOS falls through to
`stat -f %m`. Ignore any value that is not a number.

verify.sh gains a check with a lock dir dated 2020. It fails on Linux with
the old script and passes with this one.
@jeanfbrito
jeanfbrito merged commit 3bc39ca into main Oct 10, 2026
2 checks passed
@jeanfbrito
jeanfbrito deleted the fix/ledger-append-linux-stat branch October 10, 2026 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant