forked from PatchMon/PatchMon-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Labels
bugSomething isn't workingSomething isn't workingcode-qualityCode qualityCode qualitymediumMedium priorityMedium priority
Description
Description
The ping loop goroutine in WebSocket connections and the update check goroutine after report have no mechanism to stop when the connection closes or parent context is cancelled.
Locations
WebSocket ping loop
`cmd/patchmon-agent/commands/serve.go` lines 372-379
go func() {
t := time.NewTicker(30 * time.Second)
defer t.Stop()
for range t.C {
_ = conn.WriteControl(websocket.PingMessage, nil, time.Now().Add(5*time.Second))
}
}()Post-report update check
`cmd/patchmon-agent/commands/report.go` lines 247-280
go func() {
time.Sleep(5 * time.Second)
// ... update check logic with no cancellation mechanism
}()Impact
- Goroutines accumulate over time, causing memory leaks
- Resources not properly released when connections close
Recommended Fix
Pass context to goroutines and check for cancellation:
go func(ctx context.Context) {
t := time.NewTicker(30 * time.Second)
defer t.Stop()
for {
select {
case <-ctx.Done():
return
case <-t.C:
if err := conn.WriteControl(websocket.PingMessage, nil, time.Now().Add(5*time.Second)); err != nil {
return
}
}
}
}(ctx)Severity
🟡 MEDIUM - Resource leak
Labels
bug, medium, code-quality
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingcode-qualityCode qualityCode qualitymediumMedium priorityMedium priority