From 319bf56a6f7e2f26c370ebf4e35dd917a9584e61 Mon Sep 17 00:00:00 2001 From: rcourtman Date: Thu, 13 Nov 2025 20:15:05 +0000 Subject: [PATCH] Add context timeout to local temperature collection The getTemperatureLocal() function was running sensors without a timeout, which could cause HTTP requests to hang if the sensors command stalled. This adds context.Context parameter and uses exec.CommandContext to ensure local temperature collection respects the same 15-second timeout as SSH-based collection. Fixes issue where HTTP mode worked for remote nodes but timed out for self-monitoring on the same host. --- cmd/pulse-sensor-proxy/ssh.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/pulse-sensor-proxy/ssh.go b/cmd/pulse-sensor-proxy/ssh.go index 72eee94..ca2d936 100644 --- a/cmd/pulse-sensor-proxy/ssh.go +++ b/cmd/pulse-sensor-proxy/ssh.go @@ -580,7 +580,7 @@ func (p *Proxy) getTemperatureViaSSH(ctx context.Context, nodeHost string) (stri // For standalone nodes, avoid SSH and run sensors directly if isLocalNode(nodeHost) { log.Debug().Str("node", nodeHost).Msg("Self-monitoring detected, collecting temperatures locally") - return p.getTemperatureLocal() + return p.getTemperatureLocal(ctx) } privKeyPath := filepath.Join(p.sshKeyPath, "id_ed25519") @@ -1002,13 +1002,13 @@ func isLocalNode(nodeHost string) bool { } // getTemperatureLocal collects temperature data from the local machine -func (p *Proxy) getTemperatureLocal() (string, error) { - // Run the same command that the wrapper script runs - cmd := exec.Command("sensors", "-j") +func (p *Proxy) getTemperatureLocal(ctx context.Context) (string, error) { + // Run the same command that the wrapper script runs with context timeout + cmd := exec.CommandContext(ctx, "sensors", "-j") output, err := cmd.Output() if err != nil { // Try without -j flag as fallback - cmd = exec.Command("sensors") + cmd = exec.CommandContext(ctx, "sensors") output, err = cmd.Output() if err != nil { return "", fmt.Errorf("failed to run sensors: %w", err)