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 <james@tailscale.com>
dsnet/httpio
James Tucker 11 months ago committed by James Tucker
parent 5cc1bfe82d
commit ff9c1ebb4a

@ -1573,6 +1573,17 @@ func (c *sclient) sendMeshUpdates() error {
c.s.mu.Lock() c.s.mu.Lock()
defer c.s.mu.Unlock() 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 writes := 0
for _, pcs := range c.peerStateChange { for _, pcs := range c.peerStateChange {
if c.bw.Available() <= frameHeaderLen+keyLen { if c.bw.Available() <= frameHeaderLen+keyLen {

Loading…
Cancel
Save