Repository navigation
fix(docker): wait for tenderdash to exit after forwarding a signal #1607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0b99ac7
fix(docker): wait for tenderdash to exit after forwarding a signal
lklimek 49fe3de
fix(docker): keep tenderdash's exit status when it exits during the s…
lklimek 8370b72
Merge remote-tracking branch 'origin/dev' into fix/docker-entrypoint-…
lklimek 6b026c8
Merge remote-tracking branch 'origin/dev' into fix/docker-entrypoint-…
lklimek dd97674
test(docker): bound each entrypoint run in the signal test with a tim…
lklimek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| #!/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" | ||
| # 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" \ | ||
| 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 | ||
| 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" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.