Skip to content

BUG: Potential race condition in IDLE watcher Stop() #617

@andrinoff

Description

@andrinoff

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions