mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: update conn derpmap every 5s in single tailnet (#9176)
This commit is contained in:
@@ -21,6 +21,7 @@ import (
|
||||
"golang.org/x/xerrors"
|
||||
"tailscale.com/derp"
|
||||
"tailscale.com/derp/derphttp"
|
||||
"tailscale.com/tailcfg"
|
||||
"tailscale.com/types/key"
|
||||
|
||||
"cdr.dev/slog"
|
||||
@@ -119,7 +120,8 @@ type Server struct {
|
||||
SDKClient *wsproxysdk.Client
|
||||
|
||||
// DERP
|
||||
derpMesh *derpmesh.Mesh
|
||||
derpMesh *derpmesh.Mesh
|
||||
latestDERPMap *tailcfg.DERPMap
|
||||
|
||||
// Used for graceful shutdown. Required for the dialer.
|
||||
ctx context.Context
|
||||
@@ -239,17 +241,14 @@ func New(ctx context.Context, opts *Options) (*Server, error) {
|
||||
return nil, xerrors.Errorf("parse app security key: %w", err)
|
||||
}
|
||||
|
||||
connInfo, err := client.SDKClient.WorkspaceAgentConnectionInfoGeneric(ctx)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("get derpmap: %w", err)
|
||||
}
|
||||
|
||||
var agentProvider workspaceapps.AgentProvider
|
||||
if opts.Experiments.Enabled(codersdk.ExperimentSingleTailnet) {
|
||||
stn, err := coderd.NewServerTailnet(ctx,
|
||||
s.Logger,
|
||||
nil,
|
||||
connInfo.DERPMap,
|
||||
func() *tailcfg.DERPMap {
|
||||
return s.latestDERPMap
|
||||
},
|
||||
s.DialCoordinator,
|
||||
wsconncache.New(s.DialWorkspaceAgent, 0),
|
||||
s.TracerProvider,
|
||||
@@ -456,6 +455,8 @@ func (s *Server) handleRegister(_ context.Context, res wsproxysdk.RegisterWorksp
|
||||
}
|
||||
s.derpMesh.SetAddresses(addresses, false)
|
||||
|
||||
s.latestDERPMap = res.DERPMap
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"github.com/google/uuid"
|
||||
"golang.org/x/xerrors"
|
||||
"nhooyr.io/websocket"
|
||||
"tailscale.com/tailcfg"
|
||||
"tailscale.com/util/singleflight"
|
||||
|
||||
"cdr.dev/slog"
|
||||
@@ -206,9 +207,10 @@ type RegisterWorkspaceProxyRequest struct {
|
||||
}
|
||||
|
||||
type RegisterWorkspaceProxyResponse struct {
|
||||
AppSecurityKey string `json:"app_security_key"`
|
||||
DERPMeshKey string `json:"derp_mesh_key"`
|
||||
DERPRegionID int32 `json:"derp_region_id"`
|
||||
AppSecurityKey string `json:"app_security_key"`
|
||||
DERPMeshKey string `json:"derp_mesh_key"`
|
||||
DERPRegionID int32 `json:"derp_region_id"`
|
||||
DERPMap *tailcfg.DERPMap `json:"derp_map"`
|
||||
// SiblingReplicas is a list of all other replicas of the proxy that have
|
||||
// not timed out.
|
||||
SiblingReplicas []codersdk.Replica `json:"sibling_replicas"`
|
||||
|
||||
Reference in New Issue
Block a user