From f21bd45077aa282b9e5cc8a65c1ba053fd332756 Mon Sep 17 00:00:00 2001 From: acamilo Date: Fri, 2 Oct 2026 13:16:49 +0000 Subject: [PATCH] fly-feed: silence the failed write itself; the test reproduces pct exec (SIGPIPE ignored, a reader that leaves) The previous test sent stdout to /dev/null before the pipe, so head never closed it, and printf still printed its write error. With SIGPIPE ignored and a slow systemctl stub the old fly-feed prints the live error ('echo: write error: Broken pipe'); the fix prints nothing. --- infra/bin/fly-feed | 11 ++++------- infra/tests/lint.sh | 27 ++++++++++++--------------- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/infra/bin/fly-feed b/infra/bin/fly-feed index 6938e19..85fb6fc 100755 --- a/infra/bin/fly-feed +++ b/infra/bin/fly-feed @@ -129,14 +129,11 @@ page_on_feed() { page_unit_active() { systemctl is-active --quiet "$FLY_PAGE_SERVICE" 2>/dev/null; } old_invocation="" -# Print to stdout, exiting quietly if the pipe is closed (e.g. `fly-feed status | head -1`). -# bash's builtins report "write error: Broken pipe" on a failed write even with `trap '' PIPE`, -# so we check the write result ourselves and exit 0 on EPIPE: the reader is gone, nothing -# useful is left to do, and `set -e` must not trip on the failing printf. +# Print to stdout, exiting quietly once the reader has gone (`fly-feed status | head -1`). +# Under `pct exec` SIGPIPE is ignored, so a write to a closed pipe fails with EPIPE and bash's +# printf/echo print "write error: Broken pipe": silence that one write and stop printing. say() { - if ! printf '%s\n' "$*"; then - exit 0 - fi + printf '%s\n' "$*" 2>/dev/null || exit 0 } # Wait for a NEW flysim invocation to be healthy and the feed to be flowing in `via` mode. healthy() { diff --git a/infra/tests/lint.sh b/infra/tests/lint.sh index 5f9d6f0..c7305cb 100755 --- a/infra/tests/lint.sh +++ b/infra/tests/lint.sh @@ -1659,6 +1659,8 @@ mkdir -p "$ff_dir/bin" "$ff_dir/release" "$ff_dir/proc/4242" "$ff_dir/run" cat > "$ff_dir/bin/systemctl" <<'FFSTUB' #!/usr/bin/env bash echo "$*" >> "$FF_DIR/systemctl.log" +# FF_SLOW: answer is-active late, as a real systemctl does, so a reader can leave in between +[ -n "${FF_SLOW:-}" ] && [ "$1" = is-active ] && sleep 0.3 case "$1" in restart) n=$(( $(cat "$FF_DIR/invocation" 2>/dev/null || echo 1) + 1 )); echo "$n" > "$FF_DIR/invocation" # the new flysim's environment is whatever fly.env says now @@ -1720,25 +1722,20 @@ else fail "fly-feed status wrong: $ff_out" fi -# `fly-feed status | head -1` (a human reading a single line) closes stdout after the first -# line. Subsequent writes would fail with EPIPE; bash's builtins report "write error: -# Broken pipe" to stderr even with `trap '' PIPE`, so fly-feed routes every status_report -# write through a helper that exits 0 on the first EPIPE. The test runs the real fly-feed -# under the same stubbed state, captures fly-feed's stderr to a file, and asserts that -# nothing is written there. The test's stdout is not the script's stdout (it goes to a -# pipe closed by head -1), so suppress the SC2260 "this redirection overrides the -# output pipe" warning: the override is the point of the test. +# `fly-feed status | head -1` under `pct exec`, which runs commands with SIGPIPE ignored: every +# write after head exits fails with EPIPE, and bash prints "write error: Broken pipe" unless +# fly-feed stops printing quietly (seen live on 2026-10-02). Reproduce both conditions: SIGPIPE +# ignored (inherited by the script) and a reader that leaves after the first line. ff_reset direct direct FF_ARGS=(status) -: > /tmp/ff-status-pipe.err -# shellcheck disable=SC2260 -fly_feed 2>/tmp/ff-status-pipe.err >/dev/null | head -1 || true -if [ ! -s /tmp/ff-status-pipe.err ]; then - pass "fly-feed status | head -1: nothing written to stderr on a closed stdout" +ff_pipe_err="$(mktemp)" +( trap '' PIPE; export FF_SLOW=1; fly_feed 2>"$ff_pipe_err" ) | head -1 >/dev/null || true +if [ ! -s "$ff_pipe_err" ]; then + pass "fly-feed status | head -1 with SIGPIPE ignored: nothing written to stderr" else - fail "fly-feed status | head -1 wrote to stderr: $(cat /tmp/ff-status-pipe.err)" + fail "fly-feed status | head -1 wrote to stderr: $(cat "$ff_pipe_err")" fi -rm -f /tmp/ff-status-pipe.err +rm -f "$ff_pipe_err" ff_reset direct direct FF_ARGS=(bus)