mirror of
https://github.com/coder/coder.git
synced 2025-07-15 21:43:49 +00:00
fix: avoid infinite loop in agent derp-map (#8848)
This commit is contained in:
@ -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
|
||||
}
|
||||
if update.DERPMap != nil {
|
||||
err = c.rewriteDerpMap(update.DERPMap)
|
||||
if err != nil {
|
||||
update.Err = err
|
||||
update.DERPMap = nil
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
},
|
||||
|
@ -706,6 +706,10 @@ func derpMapper(logger slog.Logger, cfg *codersdk.DeploymentValues, proxyHealth
|
||||
// existing ID in the DERP map.
|
||||
regionID := int(startingRegionID) + int(status.Proxy.RegionID)
|
||||
regionCode := fmt.Sprintf("coder_%s", strings.ToLower(status.Proxy.Name))
|
||||
regionName := status.Proxy.DisplayName
|
||||
if regionName == "" {
|
||||
regionName = status.Proxy.Name
|
||||
}
|
||||
for _, r := range derpMap.Regions {
|
||||
if r.RegionID == regionID || r.RegionCode == regionCode {
|
||||
// Log a warning if we haven't logged one in the last
|
||||
@ -768,7 +772,7 @@ func derpMapper(logger slog.Logger, cfg *codersdk.DeploymentValues, proxyHealth
|
||||
EmbeddedRelay: false,
|
||||
RegionID: regionID,
|
||||
RegionCode: regionCode,
|
||||
RegionName: status.Proxy.Name,
|
||||
RegionName: regionName,
|
||||
Nodes: nodes,
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user