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