Skip to content

fix(spark): propagate exit code of the entrypoint - #1595

Open
sweb wants to merge 2 commits into
mainfrom
fix/spark-exit-code-propagation
Open

fix(spark): propagate exit code of the entrypoint#1595
sweb wants to merge 2 commits into
mainfrom
fix/spark-exit-code-propagation

Conversation

@sweb

@sweb sweb commented Jul 28, 2026

Copy link
Copy Markdown
Member

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

  • Changes are OpenShift compatible
  • All added packages (via microdnf or otherwise) have a comment on why they are added
  • Things not downloaded from Red Hat repositories should be mirrored in the Stackable repository and downloaded from there
  • All packages should have (if available) signatures/hashes verified
  • Add an entry to the CHANGELOG.md file
  • Integration tests ran successfully
TIP: Running integration tests with a new product image

The image can be built and uploaded to the kind cluster with the following commands:

boil build <IMAGE> --image-version <RELEASE_VERSION> --strip-architecture --load
kind load docker-image <MANIFEST_URI> --name=<name-of-your-test-cluster>

See the output of boil to retrieve the image manifest URI for <MANIFEST_URI>.

Comment on lines +18 to +19
while true; do
wait "$child_pid"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If "wait" returns immediately, this will be a very cpu intensive loop and that might prevent the child to actually end.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants