Skip to content

Cooldown and lock robustness in 50-git-backup.sh: a corrupt marker bypasses the throttle, and the marker is only written on success #258

Closed

Description

@fdaviddpt

Three robustness defects in hooks.d/after_save/50-git-backup.sh, all around the cooldown and lock. None is as serious as #253 or the silent stops filed alongside this; they are grouped because they share a file and a shape.

1. A corrupt cooldown marker silently bypasses the cooldown (:88-90)

    LAST_MOD=$(cat "$COOLDOWN_MARKER" 2>/dev/null || echo 0)
    ELAPSED=$(( $(date +%s) - LAST_MOD ))
    if [ "$ELAPSED" -lt "$BACKUP_COOLDOWN" ]; then

LAST_MOD is unvalidated file content fed straight into $(( )). A truncated or garbage marker — a crash mid-write, a partially synced file — makes the arithmetic error out, leaves ELAPSED empty, and then [ "" -lt 900 ] errors too. The cooldown is skipped, and the full add/rm/commit runs on every save from then on, with nothing saying why.

The fix is the same two-line numeric guard #253's PR already had to add for its rejection counter:

case "$LAST_MOD" in ''|*[!0-9]*) LAST_MOD=0 ;; esac

2. The cooldown marker is written only when the commit succeeds

So on a store where commits fail — see the sibling issue about :201 — the throttle never engages at all. The two defects compound: the store stops backing up and starts doing the full work on every single save, which is the opposite of what a cooldown is for. Neither is visible.

3. A narrow re-entrancy window on the flock path

The subshell's trap 'rm -f "$LOCK_FILE"' EXIT unlinks the lock file. If a second instance opens the file just before that rm, it locks an unlinked inode while a third instance creates a fresh one — two concurrent backups on the same store.

Lower confidence than the other two, and worth re-deriving before acting. The agent that found it checked the part that is fine — the lock lives on fd 9 and is correctly inherited by the background subshell — and argues the rm is simply unnecessary on the flock path. That is a small change, but concurrency changes deserve their own reproduction rather than a reading.

Provenance

All three found by the agent implementing #253's part 1 and reported rather than folded in. Items 1 and 2 verified independently against main (:88-90); item 3 is recorded as unverified, deliberately.

Activity

  1. added 2 commits that reference this issue on Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions