From b314d966ccb2d052f3d5e9c4c949b7c1834813c4 Mon Sep 17 00:00:00 2001 From: Ghanan Gowripalan Date: Wed, 7 Dec 2022 14:47:42 -0800 Subject: [PATCH] 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 --- pkg/tcpip/stack/gro.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/tcpip/stack/gro.go b/pkg/tcpip/stack/gro.go index b0d22d659..c59c023dd 100644 --- a/pkg/tcpip/stack/gro.go +++ b/pkg/tcpip/stack/gro.go @@ -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]