From ff9c1ebb4a056e4a12e3edff5e5a505b72a8045d Mon Sep 17 00:00:00 2001 From: James Tucker Date: Wed, 10 Jan 2024 18:16:00 -0800 Subject: [PATCH] derp: reduce excess goroutines blocking on broadcasts Observed on one busy derp node, there were 600 goroutines blocked writing to this channel, which represents not only more blocked routines than we need, but also excess wake-ups downstream as the latent goroutines writes represent no new work. Updates #self Signed-off-by: James Tucker --- derp/derp_server.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/derp/derp_server.go b/derp/derp_server.go index 2479ff5a5..f9c8ab40f 100644 --- a/derp/derp_server.go +++ b/derp/derp_server.go @@ -1573,6 +1573,17 @@ func (c *sclient) sendMeshUpdates() error { c.s.mu.Lock() defer c.s.mu.Unlock() + // allow all happened-before mesh update request goroutines to complete, if + // we don't finish the task we'll queue another below. +drainUpdates: + for { + select { + case <-c.meshUpdate: + default: + break drainUpdates + } + } + writes := 0 for _, pcs := range c.peerStateChange { if c.bw.Available() <= frameHeaderLen+keyLen {