Skip to content

Commit 0a312ac

Browse files
harp-intelclaude
andauthored
fix: preserve collected data when controller script is interrupted by signal (#671)
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 <noreply@anthropic.com>
1 parent 12abe5a commit 0a312ac

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

internal/script/script.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,16 @@ func RunScripts(myTarget target.Target, scripts []ScriptDefinition, continueOnSc
137137
return nil, err
138138
}
139139
if exitcode != 0 {
140-
slog.Error("controller script returned non-zero exit code", slog.String("stdout", stdout), slog.String("stderr", stderr), slog.Int("exitcode", exitcode))
141-
return nil, fmt.Errorf("controller script returned exit code %d", exitcode)
140+
// If the controller was interrupted (e.g., by SIGINT) but still produced output,
141+
// parse the output rather than discarding it. This handles the case where the
142+
// controller's handle_sigint exits 0 but the SSH process carrying it gets
143+
// interrupted and returns a non-zero exit code (e.g., 255).
144+
if strings.Contains(stdout, "<---------------------->") {
145+
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))
146+
} else {
147+
slog.Error("controller script returned non-zero exit code", slog.String("stdout", stdout), slog.String("stderr", stderr), slog.Int("exitcode", exitcode))
148+
return nil, fmt.Errorf("controller script returned exit code %d", exitcode)
149+
}
142150
}
143151
// parse output of controller script
144152
allScriptOutputs := parseControllerScriptOutput(stdout)

0 commit comments

Comments
 (0)