mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
fix(wsconncache): only allow one peer per connection (#5886)
If an agent went away and reconnected, the wsconncache connection would be polluted for about 10m because there would be two peers with the same IP. The old peer always had priority, which caused the dashboard to try and always dial the old peer until it was removed. Fixes: https://github.com/coder/coder/issues/5292
This commit is contained in:
@ -402,11 +402,6 @@ func (api *API) workspaceAgentListeningPorts(rw http.ResponseWriter, r *http.Req
|
||||
|
||||
func (api *API) dialWorkspaceAgentTailnet(r *http.Request, agentID uuid.UUID) (*codersdk.AgentConn, error) {
|
||||
clientConn, serverConn := net.Pipe()
|
||||
go func() {
|
||||
<-r.Context().Done()
|
||||
_ = clientConn.Close()
|
||||
_ = serverConn.Close()
|
||||
}()
|
||||
|
||||
derpMap := api.DERPMap.Clone()
|
||||
for _, region := range derpMap.Regions {
|
||||
@ -453,7 +448,16 @@ func (api *API) dialWorkspaceAgentTailnet(r *http.Request, agentID uuid.UUID) (*
|
||||
}
|
||||
|
||||
sendNodes, _ := tailnet.ServeCoordinator(clientConn, func(node []*tailnet.Node) error {
|
||||
return conn.UpdateNodes(node)
|
||||
err := conn.RemoveAllPeers()
|
||||
if err != nil {
|
||||
return xerrors.Errorf("remove all peers: %w", err)
|
||||
}
|
||||
|
||||
err = conn.UpdateNodes(node)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("update nodes: %w", err)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
conn.SetNodeCallback(sendNodes)
|
||||
go func() {
|
||||
@ -465,6 +469,10 @@ func (api *API) dialWorkspaceAgentTailnet(r *http.Request, agentID uuid.UUID) (*
|
||||
}()
|
||||
return &codersdk.AgentConn{
|
||||
Conn: conn,
|
||||
CloseFunc: func() {
|
||||
_ = clientConn.Close()
|
||||
_ = serverConn.Close()
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user