taildrop: fix theoretical race condition (#9866)

WaitGroup.Wait should not be concurrently called WaitGroup.Add.
In other words, we should not start new goroutines after shutodwn is called.
Thus, add a conditional to check that shutdown has not been called
before starting off a new waitAndDelete goroutine.

Updates tailscale/corp#14772

Signed-off-by: Joe Tsai <joetsai@digital-static.net>
pull/9846/head
Joe Tsai 1 year ago committed by GitHub
parent 756a4c43b6
commit a8fbe284b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -94,7 +94,7 @@ func (d *fileDeleter) Insert(baseName string) {
return // already queued for deletion return // already queued for deletion
} }
d.byName[baseName] = d.queue.PushBack(&deleteFile{baseName, d.clock.Now()}) d.byName[baseName] = d.queue.PushBack(&deleteFile{baseName, d.clock.Now()})
if d.queue.Len() == 1 { if d.queue.Len() == 1 && d.shutdownCtx.Err() == nil {
d.group.Go(func() { d.waitAndDelete(deleteDelay) }) d.group.Go(func() { d.waitAndDelete(deleteDelay) })
} }
} }
@ -147,7 +147,7 @@ func (d *fileDeleter) waitAndDelete(wait time.Duration) {
} }
// If there are still some files to delete, retry again later. // If there are still some files to delete, retry again later.
if d.queue.Len() > 0 { if d.queue.Len() > 0 && d.shutdownCtx.Err() == nil {
file := d.queue.Front().Value.(*deleteFile) file := d.queue.Front().Value.(*deleteFile)
retryAfter := deleteDelay - now.Sub(file.inserted) retryAfter := deleteDelay - now.Sub(file.inserted)
d.group.Go(func() { d.waitAndDelete(retryAfter) }) d.group.Go(func() { d.waitAndDelete(retryAfter) })

Loading…
Cancel
Save