Skip to content

Commit

Permalink
Merge pull request #70 from ahouene/downloader-close-overwritten-update
Browse files Browse the repository at this point in the history
Downloader: call `Close` on updates that are overwritten in `(*Downlader).LoadOnce`
  • Loading branch information
wojas authored Feb 7, 2024
2 parents e361da9 + 3431d69 commit 1e12340
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions syncer/receiver/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ func (d *Downloader) LoadOnce(ctx context.Context, ni snapshot.NameInfo) error {
// Make snapshot available to the syncer, replacing any previous one
// that has not been loaded yet.
d.r.mu.Lock()
// If we are about to replace an Update in the snapshotsByInstance map,
// we will need to Close it so as to release its concurrency limit token.
overwrittenSnap, hasOverwrittenSnap := d.r.snapshotsByInstance[d.instance]
// FIXME: use *snapshot.Update pointer in APIs with new tokens
d.r.snapshotsByInstance[d.instance] = snapshot.Update{
Snapshot: msg,
Expand All @@ -148,6 +151,12 @@ func (d *Downloader) LoadOnce(ctx context.Context, ni snapshot.NameInfo) error {
}
d.r.mu.Unlock()

if hasOverwrittenSnap {
d.l.WithField("overwritten_snapshot", overwrittenSnap.NameInfo.FullName).
Debug("Closing overwritten snapshot")
overwrittenSnap.Close()
}

t2 := time.Now()
d.l.WithFields(logrus.Fields{
"timestamp": ni.TimestampString,
Expand Down

0 comments on commit 1e12340

Please sign in to comment.