Skip to content

Commit 1e12340

Browse files
authored
Merge pull request #70 from ahouene/downloader-close-overwritten-update
Downloader: call `Close` on updates that are overwritten in `(*Downlader).LoadOnce`
2 parents e361da9 + 3431d69 commit 1e12340

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

syncer/receiver/downloader.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ func (d *Downloader) LoadOnce(ctx context.Context, ni snapshot.NameInfo) error {
130130
// Make snapshot available to the syncer, replacing any previous one
131131
// that has not been loaded yet.
132132
d.r.mu.Lock()
133+
// If we are about to replace an Update in the snapshotsByInstance map,
134+
// we will need to Close it so as to release its concurrency limit token.
135+
overwrittenSnap, hasOverwrittenSnap := d.r.snapshotsByInstance[d.instance]
133136
// FIXME: use *snapshot.Update pointer in APIs with new tokens
134137
d.r.snapshotsByInstance[d.instance] = snapshot.Update{
135138
Snapshot: msg,
@@ -148,6 +151,12 @@ func (d *Downloader) LoadOnce(ctx context.Context, ni snapshot.NameInfo) error {
148151
}
149152
d.r.mu.Unlock()
150153

154+
if hasOverwrittenSnap {
155+
d.l.WithField("overwritten_snapshot", overwrittenSnap.NameInfo.FullName).
156+
Debug("Closing overwritten snapshot")
157+
overwrittenSnap.Close()
158+
}
159+
151160
t2 := time.Now()
152161
d.l.WithFields(logrus.Fields{
153162
"timestamp": ni.TimestampString,

0 commit comments

Comments
 (0)