mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 11:07:31 +01:00
G5-5 script: bash -s heredoc launch (option A) — fix line-collapse hang
QA round 53 finding (Tier 2 m01 → M02): start_replica's SSH session
hung even on Linux (m01 native ssh, no Windows-Git-Bash quirks).
Root cause is a `\<newline>` line-collapse hazard in the
double-quoted SSH command argument:
$SSH_LAUNCH_M02 "
setsid nohup /tmp/g5-blockvolume \
--master ... \
...
> .../replica.log 2>&1 </dev/null &
disown \$! 2>/dev/null || true
sleep 1
exit 0"
The local shell processes `\<newline>` as line continuation INSIDE
the double-quoted string. The `\` at end of every option line
collapses lines, which can in some bash interactions produce a
joined argv where `&` runs into `disown` directly with no
separator. Remote bash then parses the joined statement
incorrectly, never executes `disown $!` / `sleep 1` / `exit 0`,
remains attached to the bg daemon, and SSH hangs.
The `\<newline>` substitution happens in the LOCAL shell (the one
running iterate.sh), so it's not Windows-Git-Bash-specific —
reproduces on m01 (Linux) too.
Fix per architect option (A) round 53: pipe the command body to
remote bash via `bash -s` heredoc instead of double-quoted ssh
argument.
launch_m01 <<EOF
setsid nohup CMD ARG1 ARG2 ... > LOG 2>&1 </dev/null &
disown \$! 2>/dev/null || true
sleep 1
exit 0
EOF
With heredoc + `bash -s`:
- body is piped to remote bash's stdin verbatim
- newlines are preserved literally regardless of any local
shell processing
- statement boundaries are unambiguous
- daemon command on a single line (no `\<newline>` continuations)
eliminates the entire ambiguity class
Implementation:
- new launch_m01() / launch_m02() functions handle Tier 1
(LOCAL_MODE=1, run via local `bash -s`) and Tier 2 (run via
`ssh ... bash -s`) with shared timeout-prefix logic
- start_master / start_primary / start_replica use the new
helpers + heredoc body
- removed SSH_LAUNCH_M01 / SSH_LAUNCH_M02 vars (subsumed by
launch_m01 / launch_m02)
Verified: local Tier-1-style smoke test launches a `sleep 30` bg
process, disowns it, and exits within 1.08s (the explicit `sleep
1` + overhead). Pre-fix this took ~5s (timeout fallback). The bg
process detached and ran independently. This proves all three
post-`&` statements (disown / sleep / exit) execute as separate
commands — the line-collapse hazard is structurally eliminated.
Refs: QA Tier 2 round 53 finding (Linux SSH hang); architect
option (A) ratified; option (B) `;<newline>` rejected per QA's
clarification (newlines also stripped by `\<newline>` so
semicolons alone don't help).
This commit is contained in:
1 parent
994ad4e842
commit
20d04965d9
1 file changed
+51
-44
@@ -74,12 +74,9 @@ SSH_M02="ssh ${SSH_OPTS} ${M02_HOST}"
|
||||
# Bash without GNU coreutils — install via `pacman -S coreutils` or
|
||||
# upgrade Git for Windows).
|
||||
if command -v timeout >/dev/null 2>&1; then
|
||||
SSH_LAUNCH_M01="timeout --preserve-status 15 ${SSH_M01}"
|
||||
SSH_LAUNCH_M02="timeout --preserve-status 15 ${SSH_M02}"
|
||||
LAUNCH_TIMEOUT_PREFIX="timeout --preserve-status 15"
|
||||
else
|
||||
log "WARNING: 'timeout' not found; SSH launch hangs will not be auto-killed (install GNU coreutils on Git Bash to fix)"
|
||||
SSH_LAUNCH_M01="${SSH_M01}"
|
||||
SSH_LAUNCH_M02="${SSH_M02}"
|
||||
LAUNCH_TIMEOUT_PREFIX=""
|
||||
fi
|
||||
|
||||
# --- Helpers ---
|
||||
@@ -87,6 +84,36 @@ fi
|
||||
log() { printf '\033[1;36m[g5-5]\033[0m %s\n' "$*" >&2; }
|
||||
die() { printf '\033[1;31m[g5-5 FAIL]\033[0m %s\n' "$*" >&2; collect_diagnostics fail; exit 1; }
|
||||
|
||||
# launch_m01 / launch_m02 — accept a script body on stdin and execute
|
||||
# it via `bash -s` either locally (LOCAL_MODE=1) or remote ssh
|
||||
# (LOCAL_MODE=0). Used by start_master / start_primary / start_replica
|
||||
# to launch background daemons safely.
|
||||
#
|
||||
# Architect option (A) round 53: `bash -s <<EOF ... EOF` avoids the
|
||||
# `\<newline>` line-continuation hazard that plagued the prior
|
||||
# double-quoted-ssh-arg form. With `bash -s`, the heredoc body is
|
||||
# piped to remote bash's stdin and executed line-by-line with literal
|
||||
# newlines preserved — `&` and `disown` stay on separate lines no
|
||||
# matter what the local shell does to the script source.
|
||||
#
|
||||
# Hard-capped at 15s by LAUNCH_TIMEOUT_PREFIX (if `timeout` available).
|
||||
# If launch ssh hangs, we move on; remote process is already detached.
|
||||
launch_m01() {
|
||||
if [ "${LOCAL_MODE}" = "1" ]; then
|
||||
${LAUNCH_TIMEOUT_PREFIX} bash -s
|
||||
else
|
||||
${LAUNCH_TIMEOUT_PREFIX} ssh ${SSH_OPTS} ${M01_HOST} bash -s
|
||||
fi
|
||||
}
|
||||
|
||||
launch_m02() {
|
||||
if [ "${LOCAL_MODE}" = "1" ]; then
|
||||
${LAUNCH_TIMEOUT_PREFIX} bash -s
|
||||
else
|
||||
${LAUNCH_TIMEOUT_PREFIX} ssh ${SSH_OPTS} ${M02_HOST} bash -s
|
||||
fi
|
||||
}
|
||||
|
||||
mkdir -p "${ARTIFACT_DIR}"
|
||||
|
||||
# Two-tier test mode (set BEFORE first SSH-or-bash command):
|
||||
@@ -237,59 +264,39 @@ EOF"
|
||||
|
||||
start_master() {
|
||||
log " start blockmaster on m01..."
|
||||
$SSH_LAUNCH_M01 "
|
||||
setsid nohup /tmp/g5-blockmaster \
|
||||
--authority-store ${REMOTE_RUN_DIR}/master-store \
|
||||
--listen 0.0.0.0:${M01_MASTER_PORT} \
|
||||
--topology ${REMOTE_RUN_DIR}/topology.yaml \
|
||||
--expected-slots-per-volume 2 \
|
||||
--t0-print-ready \
|
||||
> ${REMOTE_RUN_DIR}/logs/master.log 2>&1 </dev/null &
|
||||
# Architect option (A) round 53: pipe command via `bash -s`
|
||||
# heredoc instead of double-quoted ssh argument. Single-line
|
||||
# `setsid nohup ... &` (no `\<newline>` continuations) avoids
|
||||
# the local-shell line-collapse hazard that joined `&` into the
|
||||
# following `disown` statement, making remote bash wait on the
|
||||
# bg job and hang the SSH session.
|
||||
launch_m01 <<EOF
|
||||
setsid nohup /tmp/g5-blockmaster --authority-store ${REMOTE_RUN_DIR}/master-store --listen 0.0.0.0:${M01_MASTER_PORT} --topology ${REMOTE_RUN_DIR}/topology.yaml --expected-slots-per-volume 2 --t0-print-ready > ${REMOTE_RUN_DIR}/logs/master.log 2>&1 </dev/null &
|
||||
disown \$! 2>/dev/null || true
|
||||
sleep 1
|
||||
exit 0"
|
||||
exit 0
|
||||
EOF
|
||||
}
|
||||
|
||||
start_primary() {
|
||||
log " start primary blockvolume on m01..."
|
||||
$SSH_LAUNCH_M01 "
|
||||
setsid nohup /tmp/g5-blockvolume \
|
||||
--master 127.0.0.1:${M01_MASTER_PORT} \
|
||||
--server-id m01-primary --volume-id v1 --replica-id r1 \
|
||||
--ctrl-addr 0.0.0.0:${M01_PRIMARY_CTRL_PORT} \
|
||||
--data-addr 0.0.0.0:${M01_PRIMARY_DATA_PORT} \
|
||||
--status-addr 127.0.0.1:${M01_PRIMARY_STATUS_PORT} \
|
||||
--status-recovery \
|
||||
--durable-root ${REMOTE_RUN_DIR}/primary-store \
|
||||
--durable-impl ${DURABLE_IMPL} \
|
||||
--durable-blocks ${DURABLE_BLOCKS} --durable-blocksize ${DURABLE_BLOCKSIZE} \
|
||||
--iscsi-listen 127.0.0.1:${M01_ISCSI_PORT} \
|
||||
--iscsi-iqn ${ISCSI_IQN} \
|
||||
--t1-readiness \
|
||||
> ${REMOTE_RUN_DIR}/logs/primary.log 2>&1 </dev/null &
|
||||
launch_m01 <<EOF
|
||||
setsid nohup /tmp/g5-blockvolume --master 127.0.0.1:${M01_MASTER_PORT} --server-id m01-primary --volume-id v1 --replica-id r1 --ctrl-addr 0.0.0.0:${M01_PRIMARY_CTRL_PORT} --data-addr 0.0.0.0:${M01_PRIMARY_DATA_PORT} --status-addr 127.0.0.1:${M01_PRIMARY_STATUS_PORT} --status-recovery --durable-root ${REMOTE_RUN_DIR}/primary-store --durable-impl ${DURABLE_IMPL} --durable-blocks ${DURABLE_BLOCKS} --durable-blocksize ${DURABLE_BLOCKSIZE} --iscsi-listen 127.0.0.1:${M01_ISCSI_PORT} --iscsi-iqn ${ISCSI_IQN} --t1-readiness > ${REMOTE_RUN_DIR}/logs/primary.log 2>&1 </dev/null &
|
||||
disown \$! 2>/dev/null || true
|
||||
sleep 1
|
||||
exit 0"
|
||||
exit 0
|
||||
EOF
|
||||
}
|
||||
|
||||
start_replica() {
|
||||
log " start replica blockvolume on M02..."
|
||||
$SSH_LAUNCH_M02 "mkdir -p ${REMOTE_RUN_DIR}/{logs,replica-store} && \
|
||||
setsid nohup /tmp/g5-blockvolume \
|
||||
--master ${M02_MASTER_TARGET}:${M01_MASTER_PORT} \
|
||||
--server-id m02-replica --volume-id v1 --replica-id r2 \
|
||||
--ctrl-addr 0.0.0.0:${M02_REPLICA_CTRL_PORT} \
|
||||
--data-addr 0.0.0.0:${M02_REPLICA_DATA_PORT} \
|
||||
--status-addr 127.0.0.1:${M02_REPLICA_STATUS_PORT} \
|
||||
--status-recovery \
|
||||
--durable-root ${REMOTE_RUN_DIR}/replica-store \
|
||||
--durable-impl ${DURABLE_IMPL} \
|
||||
--durable-blocks ${DURABLE_BLOCKS} --durable-blocksize ${DURABLE_BLOCKSIZE} \
|
||||
--t1-readiness \
|
||||
> ${REMOTE_RUN_DIR}/logs/replica.log 2>&1 </dev/null &
|
||||
launch_m02 <<EOF
|
||||
mkdir -p ${REMOTE_RUN_DIR}/{logs,replica-store}
|
||||
setsid nohup /tmp/g5-blockvolume --master ${M02_MASTER_TARGET}:${M01_MASTER_PORT} --server-id m02-replica --volume-id v1 --replica-id r2 --ctrl-addr 0.0.0.0:${M02_REPLICA_CTRL_PORT} --data-addr 0.0.0.0:${M02_REPLICA_DATA_PORT} --status-addr 127.0.0.1:${M02_REPLICA_STATUS_PORT} --status-recovery --durable-root ${REMOTE_RUN_DIR}/replica-store --durable-impl ${DURABLE_IMPL} --durable-blocks ${DURABLE_BLOCKS} --durable-blocksize ${DURABLE_BLOCKSIZE} --t1-readiness > ${REMOTE_RUN_DIR}/logs/replica.log 2>&1 </dev/null &
|
||||
disown \$! 2>/dev/null || true
|
||||
sleep 1
|
||||
exit 0"
|
||||
exit 0
|
||||
EOF
|
||||
}
|
||||
|
||||
start_cluster() {
|
||||
|
||||
Reference in new issue
Block a user