Skip to content

fix(pg_upgrade): do not leave the status file at running when complete.sh exits - #2748

Draft
idawson-sb wants to merge 1 commit into
developfrom
fix/pg-upgrade-complete-exit-trap
Draft

idawson-sb wants to merge 1 commit into
developfrom
fix/pg-upgrade-complete-exit-trap

Conversation

@idawson-sb

Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

Bug fix.

What is the current behavior?

complete.sh writes running to /tmp/pg-upgrade-status at the start of complete_pg_upgrade. Only the ERR trap (trap cleanup ERR) writes the final status. These exits skip the ERR trap:

  • an explicit exit after the file says running;
  • a set -u abort on an unset variable;
  • a TERM or INT signal, for example when the job is stopped.

After one of these exits, the file stays at running until the host reboots. check.sh then reports a live upgrade, and the next complete.sh run stops with "Upgrade job already started. Bailing."

initiate.sh already handles this with an EXIT trap (on_exit) and TERM/INT traps. complete.sh does not.

What is the new behavior?

complete_pg_upgrade sets an EXIT trap and TERM/INT traps just after it writes running. This is the same method as initiate.sh.

  • If the file still reads running when the job exits, on_exit runs cleanup failed. This writes failed, re-enables the timers, and sends the logs, as for any other failure.
  • If the file reads complete or failed, on_exit does nothing.
  • cleanup runs in a subshell, because it calls exit. A failed run then exits non-zero.
  • The traps are set inside the function because it runs in the background, where the parent's traps do not apply.

Additional context

Test: I used a small script with the same shape as complete.sh (set -eEuo pipefail, a top-level ERR trap, the job in a background function). This is the status file after each type of exit:

How the job ends Before After
Success complete complete
Command fails (ERR trap) failed failed
Explicit exit 1 running failed
set -u abort running failed
TERM signal running failed

Not tested yet:

  • A real complete.sh run on a host. I tested only the trap method in a copy of the script's shape.
  • shfmt. It is not installed on my machine; CI checks it. I checked the syntax with bash -n.
  • Does this script change need a postgres_release version bump? Please tell me if it does.

No trap can run on SIGKILL or an OOM kill, so this change does not cover those cases.

🤖 Generated with Claude Code

…e.sh exits

complete.sh writes "running" to /tmp/pg-upgrade-status, but only an
ERR trap sets the final status. An explicit exit, a set -u abort, or a
TERM/INT signal skips that trap, so the file stays at "running".
check.sh then reports a live upgrade, and the next complete.sh run
bails with "Upgrade job already started".

Add an EXIT trap, as initiate.sh has, that writes "failed" when the
file still reads "running".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown

Package version diff

Compares built package versions in legacyPackages between this PR and the tip of the base branch, per system.

aarch64-linux: Closure size: 372 -> 372 (2 paths added, 2 paths removed, delta +0, disk usage +624B).
<<< /nix/store/9l16s6yi3fvhzvh4655nvyidkscig59g-build-ami
>>> /nix/store/916sslk8sww501iplv1m5sa1qn11gvc2-build-ami
No version or selection state changes.
Closure size: 98 -> 98 (2 paths added, 2 paths removed, delta +0, disk usage +624B).
<<< /nix/store/vg18631iv6lgslyw5sj8spwgf8rs873a-build-qemu-image
>>> /nix/store/5sjy778y9sxywwgf3rak56s2hhgg09p4-build-qemu-image
No version or selection state changes.
Closure size: 372 -> 372 (2 paths added, 2 paths removed, delta +0, disk usage +624B).
x86_64-linux: Closure size: 370 -> 370 (2 paths added, 2 paths removed, delta +0, disk usage +624B).
<<< /nix/store/p5spcvwfbxs2zb7dbsmaisdacypp4l10-build-ami
>>> /nix/store/svlfhxbwrs0vj7fp0pw742zxsnkihyyy-build-ami
No version or selection state changes.
Closure size: 99 -> 99 (2 paths added, 2 paths removed, delta +0, disk usage +624B).
<<< /nix/store/056y11rzc7kadcy1gm3sjbp6vxsn5vn3-build-qemu-image
>>> /nix/store/msralyaznrkbvhwx6rzglqy5grj4lcgw-build-qemu-image
No version or selection state changes.
Closure size: 370 -> 370 (2 paths added, 2 paths removed, delta +0, disk usage +624B).

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