fix: avoid infinite loop in agent derp-map (#8848)

This commit is contained in:
Dean Sheather
2023-08-02 13:18:46 +10:00
committed by GitHub
parent 805eaca4b7
commit 6b69970d7c
2 changed files with 20 additions and 8 deletions
+15 -7
View File
@@ -211,18 +211,26 @@ func (c *Client) DERPMapUpdates(ctx context.Context) (<-chan DERPMapUpdate, io.C
if err != nil {
update.Err = err
update.DERPMap = nil
return
}
err = c.rewriteDerpMap(update.DERPMap)
if err != nil {
update.Err = err
update.DERPMap = nil
return
if update.DERPMap != nil {
err = c.rewriteDerpMap(update.DERPMap)
if err != nil {
update.Err = err
update.DERPMap = nil
}
}
select {
case updates <- update:
case <-ctx.Done():
// Unblock the caller if they're waiting for an update.
select {
case updates <- DERPMapUpdate{Err: ctx.Err()}:
default:
}
return
}
if update.Err != nil {
return
}
}
@@ -231,8 +239,8 @@ func (c *Client) DERPMapUpdates(ctx context.Context) (<-chan DERPMapUpdate, io.C
return updates, &closer{
closeFunc: func() error {
cancelFunc()
_ = wsNetConn.Close()
<-pingClosed
_ = conn.Close(websocket.StatusGoingAway, "Listen closed")
<-updatesClosed
return nil
},