fix(spark): propagate exit code of the entrypoint - #1595
Open
sweb wants to merge 2 commits into
Open
Conversation
razvan
reviewed
Jul 29, 2026
Comment on lines
+18
to
+19
| while true; do | ||
| wait "$child_pid" |
Member
There was a problem hiding this comment.
If "wait" returns immediately, this will be a very cpu intensive loop and that might prevent the child to actually end.
Member
Author
There was a problem hiding this comment.
As I don't know, I tested it:
# ./wrapper.sh
here=$(dirname "$0")
"$here/child.sh" &
child_pid=$!
iterations=0
# shellcheck disable=SC2329
_handle_term() {
kill -TERM "$child_pid" 2>/dev/null || true
}
trap _handle_term TERM INT
while true; do
wait "$child_pid"
result=$?
iterations=$((iterations + 1))
if [ "$result" -gt 128 ] && kill -0 "$child_pid" 2>/dev/null; then
continue
fi
break
done
echo "[wrapper] loop iterations: $iterations"
echo "[wrapper] propagated result: $result"
# CPU consumed by this shell (user/sys) and by its children.
echo "[wrapper] times (shell-user shell-sys child-user child-sys):"
times
exit "$result"
# ./child.sh
trap 'echo "[child] got TERM, still shutting down"' TERM
for _ in 1 2 3 4 5 6; do sleep 0.5; done
echo "[child] done"
exit 42
# ./run-test.sh
here=$(dirname "$0")
n=${1:-1}
chmod +x "$here/child.sh" "$here/wrapper.sh"
"$here/wrapper.sh" &
w=$!
sleep 0.4
echo "=== sending $n TERM(s) to wrapper pid $w ==="
for _ in $(seq 1 "$n"); do
kill -TERM "$w" 2>/dev/null || break
done
wait "$w"
echo "=== wrapper exited with: $? ==="
Results in:
❯ ./run-test.sh 1
=== sending 1 TERM(s) to wrapper pid 2490050 ===
[child] got TERM, still shutting down
[child] done
[wrapper] loop iterations: 2
[wrapper] propagated result: 42
[wrapper] times (shell-user shell-sys child-user child-sys):
0m0,001s 0m0,001s
0m0,005s 0m0,008s
=== wrapper exited with: 42 ===
❯ ./run-test.sh 1000
=== sending 1000 TERM(s) to wrapper pid 2490314 ===
[child] got TERM, still shutting down
[child] done
[wrapper] loop iterations: 3
[wrapper] propagated result: 42
[wrapper] times (shell-user shell-sys child-user child-sys):
0m0,016s 0m0,006s
0m0,008s 0m0,009s
=== wrapper exited with: 42 ===
Does not look to me as if this spins out of control but blocks on wait.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
result=$?sat after the wait loop, so it captured the loop's status (always 0) instead of the entrypoint's.Tests are covered here: stackabletech/spark-k8s-operator#735
Definition of Done Checklist
Note
Not all of these items are applicable to all PRs, the author should update this template to only leave the boxes in that are relevant.
Please make sure all these things are done and tick the boxes
TIP: Running integration tests with a new product image
The image can be built and uploaded to the kind cluster with the following commands:
See the output of
boilto retrieve the image manifest URI for<MANIFEST_URI>.