From 69cd5c08bb675a8d3433bb83581edfe295b33352 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Tue, 1 Dec 2026 23:50:48 -0800 Subject: [PATCH] ci: a dead recorder hands its stream to cat; a sampler that will not stop is recorded If the Go event recorder itself dies or cannot start, the rest of its stream (stdout, and the stderr side) now drains through cat, so go test never writes into a closed pipe and its own exit status stays the answer. Twins with a recorder that exits after 100 bytes and a large stream: exit 0 stays 0, exit 7 stays 7. Stopping the load sampler now waits on its pidfd (readable on exit) for 2 s; a sampler still alive leaves load.incomplete beside its rows and a stderr note instead of returning as if it had flushed. The stop test checks the process is gone (no file-stability guess) and a SIGTERM- ignoring stand-in yields the note within 5 s. Co-Authored-By: Claude Opus 5.5 --- seaweed-block/.github/scripts/ci-load-test.py | 31 +++++++++++++++++-- seaweed-block/.github/scripts/ci-load.py | 10 ++++-- .../.github/scripts/record-go-test-test.sh | 17 +++++++++- .../.github/scripts/record-go-test.sh | 6 ++-- 4 files changed, 55 insertions(+), 9 deletions(-) diff --git a/seaweed-block/.github/scripts/ci-load-test.py b/seaweed-block/.github/scripts/ci-load-test.py index d7fe06c350..b09cd6903f 100644 --- a/seaweed-block/.github/scripts/ci-load-test.py +++ b/seaweed-block/.github/scripts/ci-load-test.py @@ -37,9 +37,34 @@ class LoadTest(unittest.TestCase): self.assertTrue(fields[0].endswith('+00:00')) for field in fields[1:]: json.loads(field) - before = output.read_bytes() - time.sleep(0.1) - self.assertEqual(output.read_bytes(), before) + # The sampler exited: its pid is gone, and no incomplete note. + pid = json.loads(output.with_suffix('.pid.json').read_text())['pid'] + self.assertFalse(pathlib.Path(f'/proc/{pid}').exists() and + pathlib.Path(f'/proc/{pid}/stat').read_text().split(')')[1].split()[0] != 'Z') + self.assertFalse(output.with_suffix('.incomplete').exists()) + + @unittest.skipUnless(sys.platform == 'linux', 'real /proc lifecycle is Linux-only') + def test_stop_records_a_sampler_that_does_not_exit(self): + with tempfile.TemporaryDirectory() as name: + output = pathlib.Path(name)/'load.tsv' + ready = pathlib.Path(name)/'ready' + stubborn = subprocess.Popen([sys.executable, '-c', + 'import pathlib,signal,sys,time; signal.signal(signal.SIGTERM, signal.SIG_IGN); ' + 'pathlib.Path(sys.argv[1]).touch(); time.sleep(30)', str(ready)]) + try: + while not ready.exists(): + time.sleep(0.01) + output.with_suffix('.pid.json').write_text(json.dumps(dict(pid=stubborn.pid, start=load.identity(stubborn.pid)))) + began = time.monotonic() + done = subprocess.run([sys.executable, '-I', str(pathlib.Path(__file__).with_name('ci-load.py')), 'stop', str(output)], + capture_output=True, text=True, timeout=10) + self.assertEqual(done.returncode, 0) + self.assertLess(time.monotonic()-began, 5) + self.assertIn('did not exit', output.with_suffix('.incomplete').read_text()) + self.assertIn('load evidence incomplete', done.stderr) + finally: + stubborn.kill() + stubborn.wait() def test_cpu_and_disk_interval_not_since_boot(self): # CPU: 100 ticks, 10 iowait, 5 stolen. guest ticks are already in user. diff --git a/seaweed-block/.github/scripts/ci-load.py b/seaweed-block/.github/scripts/ci-load.py index 54a4f5543f..c0fcd56407 100644 --- a/seaweed-block/.github/scripts/ci-load.py +++ b/seaweed-block/.github/scripts/ci-load.py @@ -12,6 +12,7 @@ import json import os import pathlib import re +import select import signal import subprocess import sys @@ -156,9 +157,12 @@ def main(): signal.pidfd_send_signal(handle, signal.SIGTERM) # Flush the last row before the uploader reads the file. Never # signal a reused PID and never wait indefinitely for evidence. - until = time.monotonic()+2 - while time.monotonic() < until and identity(owner['pid']) == owner['start']: - time.sleep(0.05) + # The pidfd turns readable when the sampler exits; one still + # alive after 2 s leaves load.incomplete beside its rows. + if not select.select([handle], [], [], 2)[0]: + note = args.output.with_suffix('.incomplete') + note.write_text('the sampler did not exit within 2 s of SIGTERM; its last rows may be missing\n') + print('load evidence incomplete: '+str(note), file=sys.stderr) except ProcessLookupError: pass except FileNotFoundError: diff --git a/seaweed-block/.github/scripts/record-go-test-test.sh b/seaweed-block/.github/scripts/record-go-test-test.sh index 43fd831f0e..b98de88e99 100644 --- a/seaweed-block/.github/scripts/record-go-test-test.sh +++ b/seaweed-block/.github/scripts/record-go-test-test.sh @@ -43,4 +43,19 @@ if [ "$(uname -s)" = Linux ] && [ -c /dev/full ]; then grep -q 'draining after recorder failure' "$root/console" grep -q 'test evidence unavailable' "$root/stderr" fi -echo 'record-go-test: output, timestamp, elapsed, append and exit-status controls PASS' +# The recorder itself dies after its first bytes (a crash, an OOM kill): the +# rest of a large stream still drains and Go's own status is the answer. +cat >"$root/bin/dead-recorder" <<'EOF2' +#!/usr/bin/env bash +head -c 100 >/dev/null +exit 3 +EOF2 +chmod +x "$root/bin/dead-recorder" +for want in 0 7; do + code=0 + PYTHON="$root/bin/dead-recorder" FAKE_GO_LARGE=1 FAKE_GO_EXIT=$want bash "$here/record-go-test.sh" "$root/dead.json" >"$root/console" 2>"$root/stderr" || code=$? + test "$code" = "$want" + grep -q 'draining after recorder failure' "$root/console" + grep -q 'the recorder exited' "$root/stderr" +done +echo 'record-go-test: output, timestamp, elapsed, append, dead-recorder and exit-status controls PASS' diff --git a/seaweed-block/.github/scripts/record-go-test.sh b/seaweed-block/.github/scripts/record-go-test.sh index caebc315d1..d227a8bb14 100644 --- a/seaweed-block/.github/scripts/record-go-test.sh +++ b/seaweed-block/.github/scripts/record-go-test.sh @@ -6,13 +6,15 @@ out=$1 shift mkdir -p "$(dirname "$out")" || true capture="$(dirname "$0")/go-test-output.py" -exec 3> >("${PYTHON:-python3}" -u "$capture" "${out%.json}.stderr" --raw >&2) +# A recorder that dies (or cannot start) hands the rest of its stream to cat, +# so Go never writes into a closed pipe. +exec 3> >({ "${PYTHON:-python3}" -u "$capture" "${out%.json}.stderr" --raw || cat; } >&2) stderr_pid=$! # Only Go judges the test. The readers keep draining after evidence IO errors, # so a disk-full recorder cannot turn Go's PASS into a pipeline/SIGPIPE failure. set +e go test -json "$@" 2>&3 | - "${PYTHON:-python3}" -u "$capture" "$out" + { "${PYTHON:-python3}" -u "$capture" "$out" || { echo "test evidence unavailable: the recorder exited" >&2; cat; }; } status=${PIPESTATUS[0]} set -e exec 3>&-