Skip to content

Commit 80d61da

Browse files
authored
Merge pull request #26 from beam-cloud/np/fix-concurrent-map-iteration-and-write
fix: concurrent map iteration and map write panic
2 parents b94e48c + c09c587 commit 80d61da

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

pkg/client.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,15 +330,20 @@ func (c *BlobCacheClient) manageLocalClientCache(ttl time.Duration, interval tim
330330
select {
331331
case <-ticker.C:
332332
now := time.Now()
333+
stale := make([]string, 0)
333334

334335
for hash, entry := range c.localHostCache {
335336
if now.Sub(entry.timestamp) > ttl {
336-
c.mu.Lock()
337-
delete(c.localHostCache, hash)
338-
c.mu.Unlock()
337+
stale = append(stale, hash)
339338
}
340339
}
341340

341+
c.mu.Lock()
342+
for _, hash := range stale {
343+
delete(c.localHostCache, hash)
344+
}
345+
c.mu.Unlock()
346+
342347
case <-c.ctx.Done():
343348
return
344349
}

0 commit comments

Comments
 (0)