Wait for GRO loop to stop

...before returning from groDispatcher.close.

This is to make sure that when we return from cleanup functions, the
caller can safely assume that resources have been released.

PiperOrigin-RevId: 493714729
This commit is contained in:
Ghanan Gowripalan
2022-12-07 14:58:45 -08:00
committed by gVisor bot
parent a35ca06260
commit b314d966cc
+6
View File
@@ -223,6 +223,7 @@ type groDispatcher struct {
stop chan struct{}
buckets [groNBuckets]groBucket
wg sync.WaitGroup
}
func (gd *groDispatcher) init(interval time.Duration) {
@@ -246,7 +247,11 @@ func (gd *groDispatcher) init(interval time.Duration) {
// start spawns a goroutine that flushes the GRO periodically based on the
// interval.
func (gd *groDispatcher) start(interval time.Duration) {
gd.wg.Add(1)
go func(interval time.Duration) {
defer gd.wg.Done()
var ch <-chan time.Time
if interval == 0 {
// Never run.
@@ -496,6 +501,7 @@ func (gd *groDispatcher) flushAll() {
// close stops the GRO goroutine and releases any held packets.
func (gd *groDispatcher) close() {
gd.stop <- struct{}{}
gd.wg.Wait()
for i := range gd.buckets {
bucket := &gd.buckets[i]