From 0b99ac707447ad040f8bc34e411664acf52fd421 Mon Sep 17 00:00:00 2001 From: Lukasz Klimek <842586+lklimek@users.noreply.github.com> Date: Tue, 10 Nov 2026 08:50:32 +0000 Subject: [PATCH 1/3] fix(docker): wait for tenderdash to exit after forwarding a signal A signal trapped by the entrypoint interrupts `wait`, so the script (PID 1) exited right after forwarding SIGTERM and the kernel killed tenderdash mid-shutdown. `docker stop` returned within milliseconds and the 30 s --shutdown-timeout never ran. The entrypoint now keeps waiting until tenderdash has exited and returns its exit code. Co-Authored-By: Claude Opus 5.5 --- DOCKER/docker-entrypoint.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/DOCKER/docker-entrypoint.sh b/DOCKER/docker-entrypoint.sh index bef3402f9d..173e152563 100755 --- a/DOCKER/docker-entrypoint.sh +++ b/DOCKER/docker-entrypoint.sh @@ -54,6 +54,12 @@ tenderdash "$@" 2>&1 & child=$! wait "$child" exit_code=$? +# A trapped signal interrupts wait before tenderdash exits; keep waiting so its +# graceful shutdown completes before this script (PID 1) exits. +while kill -0 "$child" 2>/dev/null; do + wait "$child" + exit_code=$? +done if [ $got_signal == false ] && [ $exit_code -ne 0 ] && [ "$1" == "start" ]; then echo "Sleeping for 10 seconds as workaround for the busy port problem. See entrypoint code for details." From 49fe3dedda7eb33d79ffba7b996780fe86bfcae3 Mon Sep 17 00:00:00 2001 From: Lukasz Klimek <842586+lklimek@users.noreply.github.com> Date: Tue, 10 Nov 2026 10:45:06 +0000 Subject: [PATCH 2/3] fix(docker): keep tenderdash's exit status when it exits during the signal handler The entrypoint checked `kill -0` to decide whether to wait again after a trapped signal interrupted `wait`. If tenderdash exited, and was reaped, between the interrupted wait and that check, the script exited with the interrupted wait's 143 instead of tenderdash's status. The signal handler now marks the wait as interrupted, and the script waits again until a wait completes uninterrupted; bash returns the saved status of a child that has already exited. DOCKER/test-entrypoint.sh checks a slow shutdown, a repeated signal, an immediate exit on the signal and a plain non-zero exit with a fake tenderdash; the release tooling workflow runs it. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/release.yml | 6 ++++ DOCKER/docker-entrypoint.sh | 16 +++++---- DOCKER/test-entrypoint.sh | 65 +++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 7 deletions(-) create mode 100755 DOCKER/test-entrypoint.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 93e94a6cb6..6137ce89e5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,6 +9,8 @@ on: - 'scripts/tests/test_docker_metadata.py' - '.github/workflows/docker.yml' - 'DOCKER/Dockerfile' + - 'DOCKER/docker-entrypoint.sh' + - 'DOCKER/test-entrypoint.sh' - 'scripts/test-local-gates.sh' - 'Makefile' - '.github/workflows/release.yml' @@ -23,6 +25,8 @@ on: - 'scripts/tests/test_docker_metadata.py' - '.github/workflows/docker.yml' - 'DOCKER/Dockerfile' + - 'DOCKER/docker-entrypoint.sh' + - 'DOCKER/test-entrypoint.sh' - 'scripts/test-local-gates.sh' - 'Makefile' - '.github/workflows/release.yml' @@ -39,6 +43,8 @@ jobs: run: python3 -B -m unittest discover -s scripts/release -p test_release.py - name: Check Docker publication contract run: python3 -B -m unittest discover -s scripts/tests -p test_docker_metadata.py + - name: Check Docker entrypoint signal handling + run: bash DOCKER/test-entrypoint.sh - name: Check lint base selection run: sh scripts/test-local-gates.sh - name: Check shell syntax diff --git a/DOCKER/docker-entrypoint.sh b/DOCKER/docker-entrypoint.sh index 173e152563..ce055ccb77 100755 --- a/DOCKER/docker-entrypoint.sh +++ b/DOCKER/docker-entrypoint.sh @@ -16,6 +16,7 @@ got_signal=false _forward_signal() { echo "Caught signal! Forwarding to tenderdash process." got_signal=true + interrupted=true kill -s "$1" "$child" } @@ -52,18 +53,19 @@ fi # Start tenderdash in the background tenderdash "$@" 2>&1 & child=$! -wait "$child" -exit_code=$? -# A trapped signal interrupts wait before tenderdash exits; keep waiting so its -# graceful shutdown completes before this script (PID 1) exits. -while kill -0 "$child" 2>/dev/null; do +# A trapped signal interrupts wait before tenderdash exits; wait again until it +# returns tenderdash's own status, so its graceful shutdown completes before +# this script (PID 1) exits. +while :; do + interrupted=false wait "$child" exit_code=$? + [ "$interrupted" = true ] || break done -if [ $got_signal == false ] && [ $exit_code -ne 0 ] && [ "$1" == "start" ]; then +if [ $got_signal == false ] && [ "$exit_code" -ne 0 ] && [ "$1" == "start" ]; then echo "Sleeping for 10 seconds as workaround for the busy port problem. See entrypoint code for details." sleep 10 fi -exit $exit_code +exit "$exit_code" diff --git a/DOCKER/test-entrypoint.sh b/DOCKER/test-entrypoint.sh new file mode 100755 index 0000000000..1467d549cf --- /dev/null +++ b/DOCKER/test-entrypoint.sh @@ -0,0 +1,65 @@ +#!/bin/bash +# Checks how docker-entrypoint.sh forwards signals and reports tenderdash's exit +# status, using a fake tenderdash on PATH. +set -euo pipefail + +entrypoint="$(cd "$(dirname "$0")" && pwd)/docker-entrypoint.sh" +work=$(mktemp -d) +trap 'rm -rf "$work"' EXIT +mkdir -p "$work/bin" "$work/home/config" + +# fake_tenderdash BODY: the fake runs BODY, then idles in an interruptible wait, +# so its traps run as soon as a signal arrives. +fake_tenderdash() { + printf '#!/bin/bash\n%s\nwhile :; do sleep 60 & wait $!; done\n' "$1" >"$work/bin/tenderdash" + chmod +x "$work/bin/tenderdash" +} + +# run_entrypoint ARG SIGNALS: starts the entrypoint, sends SIGTERM SIGNALS times +# (0.3 s apart), and prints its exit status. +run_entrypoint() { + local pid status=0 + rm -f "$work/cleaned" + PATH="$work/bin:$PATH" TMHOME="$work/home" MARKER="$work/cleaned" \ + bash "$entrypoint" "$1" >/dev/null 2>&1 & + pid=$! + sleep 0.3 + for ((i = 0; i < $2; i++)); do + kill -TERM "$pid" + sleep 0.3 + done + wait "$pid" || status=$? + echo "$status" +} + +fail() { + echo "FAIL: $*" >&2 + exit 1 +} + +# Tenderdash finishes a slow shutdown before the entrypoint exits, and its +# exit status is kept. +# shellcheck disable=SC2016 # expanded by the fake tenderdash +fake_tenderdash 'trap "sleep 1; touch \"\$MARKER\"; exit 7" TERM' +status=$(run_entrypoint start 1) +[ -f "$work/cleaned" ] || fail "entrypoint exited before tenderdash finished its shutdown" +[ "$status" = 7 ] || fail "slow shutdown: want status 7, got $status" + +# A second signal during the shutdown does not end the wait. +status=$(run_entrypoint start 2) +[ -f "$work/cleaned" ] || fail "second signal: entrypoint exited before tenderdash finished" +[ "$status" = 7 ] || fail "second signal: want status 7, got $status" + +# Tenderdash exiting at once on the signal still reports its own status. +fake_tenderdash 'trap "exit 0" TERM' +for _ in $(seq 20); do + status=$(run_entrypoint start 1) + [ "$status" = 0 ] || fail "immediate exit after signal: want status 0, got $status" +done + +# Without a signal, the entrypoint returns tenderdash's status. +printf '#!/bin/bash\nexit 3\n' >"$work/bin/tenderdash" +status=$(run_entrypoint version 0) +[ "$status" = 3 ] || fail "plain exit: want status 3, got $status" + +echo "docker-entrypoint.sh: all checks passed" From dd9767418a6b19153bfe820d8c9be931f67db060 Mon Sep 17 00:00:00 2001 From: Lukasz Klimek <842586+lklimek@users.noreply.github.com> Date: Tue, 10 Nov 2026 12:53:15 +0000 Subject: [PATCH 3/3] test(docker): bound each entrypoint run in the signal test with a timeout A wedged entrypoint now fails the check instead of hanging the job. --foreground keeps timeout from signalling the fake tenderdash directly, so the test still proves the entrypoint forwards the signal, and --preserve-status reports the entrypoint's own exit status. Co-Authored-By: Claude Opus 5.5 --- DOCKER/test-entrypoint.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/DOCKER/test-entrypoint.sh b/DOCKER/test-entrypoint.sh index 1467d549cf..397dd4c26d 100755 --- a/DOCKER/test-entrypoint.sh +++ b/DOCKER/test-entrypoint.sh @@ -20,8 +20,11 @@ fake_tenderdash() { run_entrypoint() { local pid status=0 rm -f "$work/cleaned" + # A wedged run fails instead of hanging CI. --foreground keeps timeout from + # signalling the fake tenderdash itself; --preserve-status passes on the + # entrypoint's status after timeout forwards our SIGTERM to it. PATH="$work/bin:$PATH" TMHOME="$work/home" MARKER="$work/cleaned" \ - bash "$entrypoint" "$1" >/dev/null 2>&1 & + timeout --foreground --preserve-status -k 5 60 bash "$entrypoint" "$1" >/dev/null 2>&1 & pid=$! sleep 0.3 for ((i = 0; i < $2; i++)); do