Skip to content

Commit

Permalink
add stop once avoid multi close
Browse files Browse the repository at this point in the history
  • Loading branch information
ucwong committed May 24, 2024
1 parent 9c52dc1 commit 12be343
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions tracker_scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"net"
"net/url"
"sync"
"time"

"github.com/anacrolix/dht/v2/krpc"
Expand All @@ -24,7 +25,8 @@ type trackerScraper struct {
lastAnnounce trackerAnnounceResult
lookupTrackerIp func(*url.URL) ([]net.IP, error)

stopCh chan struct{}
stopOnce sync.Once
stopCh chan struct{}
}

type torrentTrackerAnnouncer interface {
Expand Down Expand Up @@ -207,7 +209,9 @@ func (me *trackerScraper) canIgnoreInterval(notify *<-chan struct{}) bool {
}

func (me *trackerScraper) Stop() {
close(me.stopCh)
me.stopOnce.Do(func() {
close(me.stopCh)
})
}

func (me *trackerScraper) Run() {
Expand Down

0 comments on commit 12be343

Please sign in to comment.