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.
This commit is contained in:
parent
9cb151d836
commit
319bf56a6f
1 changed files with 5 additions and 5 deletions
|
|
@ -580,7 +580,7 @@ func (p *Proxy) getTemperatureViaSSH(ctx context.Context, nodeHost string) (stri
|
||||||
// For standalone nodes, avoid SSH and run sensors directly
|
// For standalone nodes, avoid SSH and run sensors directly
|
||||||
if isLocalNode(nodeHost) {
|
if isLocalNode(nodeHost) {
|
||||||
log.Debug().Str("node", nodeHost).Msg("Self-monitoring detected, collecting temperatures locally")
|
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")
|
privKeyPath := filepath.Join(p.sshKeyPath, "id_ed25519")
|
||||||
|
|
@ -1002,13 +1002,13 @@ func isLocalNode(nodeHost string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// getTemperatureLocal collects temperature data from the local machine
|
// getTemperatureLocal collects temperature data from the local machine
|
||||||
func (p *Proxy) getTemperatureLocal() (string, error) {
|
func (p *Proxy) getTemperatureLocal(ctx context.Context) (string, error) {
|
||||||
// Run the same command that the wrapper script runs
|
// Run the same command that the wrapper script runs with context timeout
|
||||||
cmd := exec.Command("sensors", "-j")
|
cmd := exec.CommandContext(ctx, "sensors", "-j")
|
||||||
output, err := cmd.Output()
|
output, err := cmd.Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Try without -j flag as fallback
|
// Try without -j flag as fallback
|
||||||
cmd = exec.Command("sensors")
|
cmd = exec.CommandContext(ctx, "sensors")
|
||||||
output, err = cmd.Output()
|
output, err = cmd.Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("failed to run sensors: %w", err)
|
return "", fmt.Errorf("failed to run sensors: %w", err)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue