- Notifications
You must be signed in to change notification settings - Fork928
fix: use a background context when piping derp connections#6750
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -294,7 +294,7 @@ func (api *API) workspaceAgentPTY(rw http.ResponseWriter, r *http.Request) { | ||
gohttpapi.Heartbeat(ctx,conn) | ||
agentConn,release,err:=api.workspaceAgentCache.Acquire(workspaceAgent.ID) | ||
iferr!=nil { | ||
_=conn.Close(websocket.StatusInternalError,httpapi.WebsocketCloseSprintf("dial workspace agent: %s",err)) | ||
return | ||
@@ -339,7 +339,7 @@ func (api *API) workspaceAgentListeningPorts(rw http.ResponseWriter, r *http.Req | ||
return | ||
} | ||
agentConn,release,err:=api.workspaceAgentCache.Acquire(workspaceAgent.ID) | ||
iferr!=nil { | ||
httpapi.Write(ctx,rw,http.StatusInternalServerError, codersdk.Response{ | ||
Message:"Internal error dialing workspace agent.", | ||
@@ -414,10 +414,8 @@ func (api *API) workspaceAgentListeningPorts(rw http.ResponseWriter, r *http.Req | ||
httpapi.Write(ctx,rw,http.StatusOK,portsResponse) | ||
} | ||
func (api*API)dialWorkspaceAgentTailnet(agentID uuid.UUID) (*codersdk.WorkspaceAgentConn,error) { | ||
clientConn,serverConn:=net.Pipe() | ||
conn,err:=tailnet.NewConn(&tailnet.Options{ | ||
Addresses: []netip.Prefix{netip.PrefixFrom(tailnet.IP(),128)}, | ||
DERPMap:api.DERPMap, | ||
@@ -428,6 +426,7 @@ func (api *API) dialWorkspaceAgentTailnet(r *http.Request, agentID uuid.UUID) (* | ||
_=serverConn.Close() | ||
returnnil,xerrors.Errorf("create tailnet conn: %w",err) | ||
} | ||
ctx,cancel:=context.WithCancel(api.ctx) | ||
conn.SetDERPRegionDialer(func(_ context.Context,region*tailcfg.DERPRegion) net.Conn { | ||
if!region.EmbeddedRelay { | ||
returnnil | ||
@@ -437,7 +436,7 @@ func (api *API) dialWorkspaceAgentTailnet(r *http.Request, agentID uuid.UUID) (* | ||
deferleft.Close() | ||
deferright.Close() | ||
brw:=bufio.NewReadWriter(bufio.NewReader(right),bufio.NewWriter(right)) | ||
api.DERPServer.Accept(ctx,right,brw,"internal") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I wrote this on the previous version of this PR, but I guess the suggestion still applies: How do we avoid leaks here? Is Should we actually do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Ahh, good point! Will fix. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Fixed! | ||
}() | ||
returnleft | ||
}) | ||
@@ -453,14 +452,15 @@ func (api *API) dialWorkspaceAgentTailnet(r *http.Request, agentID uuid.UUID) (* | ||
agentConn:=&codersdk.WorkspaceAgentConn{ | ||
Conn:conn, | ||
CloseFunc:func() { | ||
cancel() | ||
_=clientConn.Close() | ||
_=serverConn.Close() | ||
}, | ||
} | ||
gofunc() { | ||
err:= (*api.TailnetCoordinator.Load()).ServeClient(serverConn,uuid.New(),agentID) | ||
iferr!=nil { | ||
api.Logger.Warn(ctx,"tailnet coordinator client error",slog.Error(err)) | ||
_=agentConn.Close() | ||
} | ||
}() | ||