Skip to content

Commit

Permalink
taildrop: fix theoretical race condition (tailscale#9866)
Browse files Browse the repository at this point in the history
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>
Signed-off-by: Alex Paguis <alex@windscribe.com>
  • Loading branch information
dsnet authored and alexelisenko committed Feb 15, 2024
1 parent 0979dc5 commit e9cb4de
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions taildrop/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (d *fileDeleter) Insert(baseName string) {
return // already queued for deletion
}
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) })
}
}
Expand Down Expand Up @@ -147,7 +147,7 @@ func (d *fileDeleter) waitAndDelete(wait time.Duration) {
}

// 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)
retryAfter := deleteDelay - now.Sub(file.inserted)
d.group.Go(func() { d.waitAndDelete(retryAfter) })
Expand Down

0 comments on commit e9cb4de

Please sign in to comment.