Skip to content

Commit 834b172

Browse files
committed
feat(scripts): M5a — 4 gemini medium fixes on PR #924 (cleanup, nc, helper-presence)
gemini-code-assist medium findings on f618144: * helper-binary presence guard (line 75) — with --no-rebuild, $ROUTE_KEY_BIN / $LIST_ROUTES_BIN may not exist; the script would fail with a misleading 'No such file or directory' buried in set -e output. Added a for-loop guard that checks all three helpers ([$ROUTE_KEY_BIN, $LIST_ROUTES_BIN, $BINARY]) up-front and exits 1 with a clear remediation message. * nc -> /dev/tcp (line 140) — bash's built-in (echo > /dev/tcp/127.0.0.1/63801) probe works on minimal CI images that don't ship netcat. Same semantics (succeeds iff the port accepts a TCP connection); no behavioural change. * trap stop_cluster EXIT INT TERM (line 99) — installed BEFORE the cluster launch so an exception during launch (bind-port collision, missing flag) still tears down the half-started state. Covers normal exit, Ctrl-C, and CI cancellation. * trailing manual stop_cluster removed (line 184) — the EXIT trap is the canonical teardown path; calling stop_cluster manually would double-call on success (harmless but noisy). Verification: bash -n scripts/run-jepsen-m5-local.sh -> OK.
1 parent f618144 commit 834b172

1 file changed

Lines changed: 30 additions & 5 deletions

File tree

scripts/run-jepsen-m5-local.sh

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,18 @@ fi
7171
# the elastickv-route-key Go helper rather than inlined in shell so
7272
# the base64 encoding stays in sync with adapter/dynamodb.go's
7373
# encodeDynamoSegment (codex P1 #1 on PR #905 ffb9c73f).
74+
#
75+
# When --no-rebuild is set, every helper binary must already exist
76+
# from a previous run; fail fast with a clear message rather than
77+
# letting `set -e` swallow a misleading 'No such file or directory'
78+
# (gemini medium on PR #924).
79+
for bin in "$ROUTE_KEY_BIN" "$LIST_ROUTES_BIN" "$BINARY"; do
80+
if [ ! -x "$bin" ]; then
81+
echo "[error] required helper not found at $bin." >&2
82+
echo " Re-run without --no-rebuild to compile the helpers." >&2
83+
exit 1
84+
fi
85+
done
7486
T1_KEY="$("$ROUTE_KEY_BIN" jepsen_append_t1)"
7587
T3_KEY="$("$ROUTE_KEY_BIN" jepsen_append_t3)"
7688
# Group 1: [T1_KEY, T3_KEY) — tables 1, 2
@@ -93,6 +105,14 @@ stop_cluster() {
93105

94106
# ---- start cluster: ONE process hosting both groups ----
95107
if ! $NO_CLUSTER; then
108+
# Install the cleanup hook BEFORE starting the cluster so an
109+
# exception during launch (e.g. bind-port collision) still
110+
# tears down the half-started state. EXIT covers normal flow,
111+
# INT/TERM cover user Ctrl-C and CI cancellation. Without
112+
# this the failure path leaks background processes that hold
113+
# the Raft / Dynamo ports for the next run (gemini medium on
114+
# PR #924).
115+
trap stop_cluster EXIT INT TERM
96116
stop_cluster
97117
rm -rf "$DATA_DIR"
98118
mkdir -p "$DATA_DIR"
@@ -134,7 +154,10 @@ if ! $NO_CLUSTER; then
134154

135155
echo "[cluster] waiting for Dynamo endpoint ($DYNAMO_ADDR)..."
136156
for i in $(seq 1 90); do
137-
if nc -z 127.0.0.1 63801; then
157+
# Use bash's built-in /dev/tcp probe rather than `nc` so the
158+
# script runs on minimal CI images that may not ship netcat
159+
# (gemini medium on PR #924).
160+
if (echo > /dev/tcp/127.0.0.1/63801) >/dev/null 2>&1; then
138161
echo "[cluster] up after ${i}s"
139162
break
140163
fi
@@ -178,9 +201,11 @@ HOME="$(pwd)/tmp-home" LEIN_HOME="$(pwd)/.lein" \
178201
EXIT_CODE=${EXIT_CODE:-0}
179202

180203
# ---- teardown ----
181-
if ! $NO_CLUSTER; then
182-
echo "[cluster] stopping..."
183-
stop_cluster
184-
fi
204+
# Cluster shutdown is handled by the `trap stop_cluster EXIT INT TERM`
205+
# installed above the cluster launch. No explicit teardown call is
206+
# needed here; doing so would double-call stop_cluster on success
207+
# (harmless but noisy) and double-call on failure (which is also
208+
# harmless since stop_cluster is idempotent, but the EXIT trap path
209+
# is the canonical one — see gemini medium on PR #924).
185210

186211
exit "$EXIT_CODE"

0 commit comments

Comments
 (0)