From 7217cccc913ca1eefa26a63e9af8b7346f24485b Mon Sep 17 00:00:00 2001 From: houseme Date: Sat, 8 Aug 2026 23:09:39 +0800 Subject: [PATCH] fix: isolate ssh stdin in hotpath artifact collection (#5851) Co-authored-by: heihutu --- scripts/collect_remote_samply_artifacts.sh | 2 +- scripts/test_collect_remote_samply_artifacts.sh | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/scripts/collect_remote_samply_artifacts.sh b/scripts/collect_remote_samply_artifacts.sh index e41ced734..51d822bc0 100755 --- a/scripts/collect_remote_samply_artifacts.sh +++ b/scripts/collect_remote_samply_artifacts.sh @@ -89,7 +89,7 @@ while IFS= read -r line || [[ -n "$line" ]]; do quoted_remote_dir=$(shell_quote "$remote_dir") remote_cmd="chmod -R a+rX $quoted_remote_dir; find $quoted_remote_dir -maxdepth 1 -type f -printf '%f %s bytes\n'" - "$SSH_BIN" "$node" "sudo su - root -c $(shell_quote "$remote_cmd")" >"$OUT_DIR/${node}-files.txt" 2>&1 + "$SSH_BIN" "$node" "sudo su - root -c $(shell_quote "$remote_cmd")" >"$OUT_DIR/${node}-files.txt" 2>&1 "$OUT_DIR/${node}-scp.err" processed=$((processed + 1)) done <"$MAPPING" diff --git a/scripts/test_collect_remote_samply_artifacts.sh b/scripts/test_collect_remote_samply_artifacts.sh index 2c2654553..edc848b4c 100755 --- a/scripts/test_collect_remote_samply_artifacts.sh +++ b/scripts/test_collect_remote_samply_artifacts.sh @@ -11,6 +11,10 @@ mkdir -p "$mock_bin" cat >"$mock_bin/ssh" <<'EOF' #!/usr/bin/env bash set -euo pipefail +if read -r consumed; then + printf 'ssh-consumed-stdin:%s\n' "$consumed" >>"$CALL_LOG" + exit 24 +fi printf 'ssh:%s\n' "$*" >>"$CALL_LOG" echo "profile.json.gz 128 bytes" echo "profile.syms.json 64 bytes" @@ -47,7 +51,12 @@ output=$("$repo_root/scripts/collect_remote_samply_artifacts.sh" \ [[ "$output" == "collected_nodes=2" ]] [[ -f "$tmp_dir/out/vm004/copied-profile.json.gz" ]] [[ -f "$tmp_dir/out/vm005/copied-profile.json.gz" ]] +[[ "$(grep -c '^ssh:' "$CALL_LOG")" -eq 2 ]] [[ "$(grep -c '^scp:' "$CALL_LOG")" -eq 2 ]] +if grep -q '^ssh-consumed-stdin:' "$CALL_LOG"; then + echo "ssh consumed the mapping loop stdin" >&2 + exit 1 +fi if grep -q '^scp-consumed-stdin:' "$CALL_LOG"; then echo "scp consumed the mapping loop stdin" >&2 exit 1