Skip to content

Commit 49ef790

Browse files
fix(scripts): validate MAX_PARALLEL and fix zombie processes on exit
- Validate MAX_PARALLEL is a positive integer, exit with clear error otherwise (prevents infinite hang with 0 or crash with non-numeric) - Consolidate 3 separate trap EXIT calls into one — they were overwriting each other, so only the last one ran (pre-existing bug causing kubectl port-forward zombies and TMPDIR not being cleaned) - Remove unused kanikoLogsPid variable Assisted-by: Claude Code Co-Authored-By: Claude Code <noreply@anthropic.com>
1 parent 2e43df9 commit 49ef790

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

.rhdh/scripts/install-rhdh-catalog-source.sh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ NAMESPACE_SUBSCRIPTION="rhdh-operator"
1414
OLM_CHANNEL="fast"
1515
UPSTREAM_IIB_OVERRIDE=""
1616
INSTALL_PLAN_APPROVAL="Automatic"
17-
MAX_PARALLEL="${MAX_PARALLEL:-10}" # max concurrent bundle workers in process_bundle
17+
MAX_PARALLEL="${MAX_PARALLEL:-10}"
18+
if ! [[ "$MAX_PARALLEL" =~ ^[0-9]+$ ]] || [[ "$MAX_PARALLEL" -lt 1 ]]; then
19+
echo "[ERROR] MAX_PARALLEL must be a positive integer, got: '$MAX_PARALLEL'" >&2
20+
exit 1
21+
fi
1822

1923
function logf() {
2024
set -euo pipefail
@@ -475,7 +479,6 @@ EOF
475479
cat "${registry_port_fwd_out}"
476480
return 1
477481
fi
478-
trap '[[ -n "${port_fwd_pid:-}" ]] && kill ${port_fwd_pid} || true' EXIT
479482

480483
local portFwdLocalPort
481484
portFwdLocalPort=$(grep -oP '127\.0\.0\.1:\K[0-9]+' "${registry_port_fwd_out}")
@@ -526,7 +529,6 @@ EOF
526529
local timestamp
527530
local kanikoJobName
528531
local kanikoPod
529-
local kanikoLogsPid
530532
local localContext
531533
timestamp=$(date +%s)
532534
kanikoJobName="kaniko-build-${timestamp}"
@@ -590,8 +592,6 @@ EOF
590592
debugf "Waiting for Kaniko pod $kanikoPod to be ready..." >&2
591593
invoke_cluster_cli -n "${namespace}" wait --for=condition=Ready "pod/$kanikoPod" --timeout=60s >&2
592594
invoke_cluster_cli -n "${namespace}" logs -f "${kanikoPod}" >&2 &
593-
kanikoLogsPid=$!
594-
trap '[[ -n "${kanikoLogsPid:-}" ]] && kill ${kanikoLogsPid} &>/dev/null || true' EXIT
595595

596596
localContext=context.tar.gz
597597
tar -czf "${localContext}" -C rhdh . >&2
@@ -624,8 +624,9 @@ fi
624624
TMPDIR=$(mktemp -d)
625625
pushd "${TMPDIR}" > /dev/null
626626
debugf ">>> WORKING DIR: $TMPDIR <<<"
627+
627628
# shellcheck disable=SC2064
628-
trap "rm -fr $TMPDIR || true" EXIT
629+
trap "rm -fr $TMPDIR || true; kill 0" EXIT INT TERM
629630

630631
detect_ocp_and_set_env_var
631632
if [[ "${IS_OPENSHIFT}" = "true" ]]; then

0 commit comments

Comments
 (0)