Skip to content

Commit f6cbf4e

Browse files
committed
fix: guard procCache.runLoop against panic leaving goroutine state corrupted
If runLoop panicked before closing firstReadyCh, callers would block until context timeout, and s.running would remain true blocking all future restarts. Defer now unconditionally resets s.running=false and closes firstReadyCh when the panic happens before the first result is emitted.
1 parent 82f8234 commit f6cbf4e

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

pkg/wshrpc/wshremote/processviewer.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,29 @@ func (s *procCacheState) requestAndWait(ctx context.Context) (*wshrpc.ProcessLis
8989
}
9090

9191
func (s *procCacheState) runLoop(firstReadyCh chan struct{}) {
92+
firstDone := false
9293
defer func() {
9394
panichandler.PanicHandler("procCache.runLoop", recover())
95+
// Always clean up running state so future requests can restart the goroutine.
96+
s.lock.Lock()
97+
if !firstDone {
98+
// Panic before first result: close channel so waiters unblock and get the
99+
// "process list unavailable" error path via the nil cached check.
100+
close(firstReadyCh)
101+
s.ready = nil
102+
}
103+
s.running = false
104+
s.lastCPUSamples = nil
105+
s.lastCPUEpoch = 0
106+
s.uidCache = nil
107+
s.lock.Unlock()
94108
}()
95109

96110
numCPU := runtime.NumCPU()
97111
if numCPU < 1 {
98112
numCPU = 1
99113
}
100114

101-
firstDone := false
102-
103115
for {
104116
iterStart := time.Now()
105117

0 commit comments

Comments
 (0)