Skip to content

Commit

Permalink
downloader: call Close on updates that are overwritten in `(*Downlo…
Browse files Browse the repository at this point in the history
…ader).LoadOnce`

When an update is replaced in `(*Downloader).LoadOnce`,
the concurrency token issued by `d.r.decompressedSnapshotLimit`
is lost and can no longer be accessed, and thus be released.
  • Loading branch information
ahouene committed Jan 25, 2024
1 parent e361da9 commit 3431d69
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 3431d69

Please sign in to comment.