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:
parent
81f4b5fee4
commit
b40a33fd2b
1 changed files with 64 additions and 67 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue