From 1f8872e64e07b95360be1744dccb674c58c9c5e2 Mon Sep 17 00:00:00 2001 From: "Harper, Jason M" Date: Wed, 25 Mar 2026 11:15:48 -0700 Subject: [PATCH] fix: preserve collected data when controller script is interrupted by signal When SIGINT is sent during flamegraph (or telemetry) collection, the controller script handles it gracefully and outputs collected data before exiting. However, the SSH process carrying the output gets interrupted by perfspect's signal handler, returning exit code 255. Previously this caused all collected data to be discarded. Now, when the controller exit code is non-zero but stdout contains valid controller output, the data is parsed and returned instead of being treated as a fatal error. Co-Authored-By: Claude Opus 4.6 --- internal/script/script.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/internal/script/script.go b/internal/script/script.go index a3767c15..00bd8091 100644 --- a/internal/script/script.go +++ b/internal/script/script.go @@ -137,8 +137,16 @@ func RunScripts(myTarget target.Target, scripts []ScriptDefinition, continueOnSc return nil, err } if exitcode != 0 { - slog.Error("controller script returned non-zero exit code", slog.String("stdout", stdout), slog.String("stderr", stderr), slog.Int("exitcode", exitcode)) - return nil, fmt.Errorf("controller script returned exit code %d", exitcode) + // If the controller was interrupted (e.g., by SIGINT) but still produced output, + // parse the output rather than discarding it. This handles the case where the + // controller's handle_sigint exits 0 but the SSH process carrying it gets + // interrupted and returns a non-zero exit code (e.g., 255). + if strings.Contains(stdout, "<---------------------->") { + slog.Warn("controller script returned non-zero exit code, but output is available and will be processed", slog.Int("exitcode", exitcode), slog.String("stderr", stderr)) + } else { + slog.Error("controller script returned non-zero exit code", slog.String("stdout", stdout), slog.String("stderr", stderr), slog.Int("exitcode", exitcode)) + return nil, fmt.Errorf("controller script returned exit code %d", exitcode) + } } // parse output of controller script allScriptOutputs := parseControllerScriptOutput(stdout)