matcha icon indicating copy to clipboard operation
matcha copied to clipboard

BUG: Potential race condition in IDLE watcher Stop()

Open andrinoff opened this issue 7 months ago • 2 comments

Describe the bug

In fetcher/idle.go lines 43-71, Stop() and StopAll() methods close stop channel, but:

  • Multiple concurrent calls could attempt closing same channel
  • done channel read in StopAllAndWait() lacks synchronization
  • Race condition if Stop() and StopAll() called simultaneously
func (w *IdleWatcher) Stop() {
    close(w.stop)  // Panic if already closed
}

To reproduce

  1. Start IDLE watcher
  2. Call Stop() twice concurrently
  3. Panic: "close of closed channel"

Expected behavior

Use sync.Once or check-then-close pattern:

type IdleWatcher struct {
    stop     chan struct{}
    stopOnce sync.Once
    // ...
}

func (w *IdleWatcher) Stop() {
    w.stopOnce.Do(func() {
        close(w.stop)
    })
}

Screenshots

N/A

Additional context

  • File: fetcher/idle.go
  • Lines: 43-50, 63-71
  • Severity: Medium - panic on concurrent stop
  • Fix complexity: Medium - add sync.Once pattern

andrinoff avatar Apr 16 '26 20:04 andrinoff

This has had no activity for 30 days. It will be closed in 14 days unless updated. Comment or remove the stale label to keep it open.

floatpanebot avatar May 17 '26 05:05 floatpanebot

Closing due to inactivity. Reopen if still relevant.

floatpanebot avatar May 31 '26 06:05 floatpanebot