Skip to content

Commit 22f955c

Browse files
committed
Fix regression: race condition in downloader.go
1 parent 827a864 commit 22f955c

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

pkg/fetching/downloader.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ type Downloader struct {
3535
handler DownloadProgressHandler
3636
client *http.Client
3737
ctx context.Context
38-
seenFingerprints map[string]bool
38+
seenFingerprints *sync.Map
3939
}
4040

4141
func NewDownloader(ctx context.Context, handler DownloadProgressHandler) *Downloader {
42-
return &Downloader{handler: handler, client: MakeClient(), ctx: ctx, seenFingerprints: make(map[string]bool)}
42+
return &Downloader{handler: handler, client: MakeClient(), ctx: ctx, seenFingerprints: &sync.Map{}}
4343
}
4444

4545
func (downloader *Downloader) downloadInitiatedSuccessfully(dl *Download) {
@@ -52,8 +52,7 @@ func (downloader *Downloader) downloadInitiatedSuccessfully(dl *Download) {
5252
cert := dl.response.TLS.PeerCertificates[0]
5353
sha1Sum := sha1.Sum(cert.Raw)
5454
sha1SumHex := hex.EncodeToString(sha1Sum[:])
55-
if _, ok := downloader.seenFingerprints[sha1SumHex]; !ok {
56-
downloader.seenFingerprints[sha1SumHex] = true
55+
if _, loaded := downloader.seenFingerprints.LoadOrStore(sha1SumHex, true); !loaded {
5756
log.Printf("Seeing new fingerprint %s (sha1) for host %v", sha1SumHex, dl.request.Host)
5857
}
5958
}

0 commit comments

Comments
 (0)