fix: prevent context leak in temperature collection

- Use defer for tempCancel() to ensure context is always cancelled
- Remove redundant shouldCollect variable that was always true
- Fix indentation after removing the unnecessary conditional block
This commit is contained in:
rcourtman 2025-11-26 23:43:18 +00:00
parent 81f4b5fee4
commit b40a33fd2b

View file

@ -2087,12 +2087,12 @@ func (m *Monitor) pollPVENode(
}
if effectiveStatus == "online" && m.tempCollector != nil && tempMonitoringEnabled {
tempCtx, tempCancel := context.WithTimeout(ctx, 30*time.Second) // Increased to accommodate SSH operations via proxy
defer tempCancel()
// Determine SSH hostname to use (most robust approach):
// Prefer the resolved host for this node, with cluster overrides when available.
sshHost := modelNode.Host
foundNodeEndpoint := false
shouldCollect := true
if modelNode.IsClusterMember && instanceCfg.IsCluster {
// Try to find specific endpoint configuration for this node
@ -2119,14 +2119,12 @@ func (m *Monitor) pollPVENode(
}
}
if shouldCollect {
if strings.TrimSpace(sshHost) == "" {
sshHost = node.Node
}
// Use HTTP proxy if configured for this instance, otherwise fall back to socket/SSH
temp, err := m.tempCollector.CollectTemperatureWithProxy(tempCtx, sshHost, node.Node, instanceCfg.TemperatureProxyURL, instanceCfg.TemperatureProxyToken)
tempCancel()
if err == nil && temp != nil && temp.Available {
// Get the current CPU temperature (prefer package, fall back to max)
@ -2196,7 +2194,6 @@ func (m *Monitor) pollPVENode(
Msg("Temperature data unavailable after collection")
}
}
}
if m.pollMetrics != nil {
nodeNameLabel := strings.TrimSpace(node.Node)