Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita9bdbdb

Browse files
fix(coderd): ensure agent WebSocket conn is cleaned up (#19711) (#20093)
Co-authored-by: Danielle Maywood <danielle@themaywoods.com>
1 parentf51e22d commita9bdbdb

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

‎coderd/workspaceagents.go‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -817,12 +817,13 @@ func (api *API) watchWorkspaceAgentContainers(rw http.ResponseWriter, r *http.Re
817817
var (
818818
ctx=r.Context()
819819
workspaceAgent=httpmw.WorkspaceAgentParam(r)
820+
logger=api.Logger.Named("agent_container_watcher").With(slog.F("agent_id",workspaceAgent.ID))
820821
)
821822

822823
// If the agent is unreachable, the request will hang. Assume that if we
823824
// don't get a response after 30s that the agent is unreachable.
824-
dialCtx,cancel:=context.WithTimeout(ctx,30*time.Second)
825-
defercancel()
825+
dialCtx,dialCancel:=context.WithTimeout(ctx,30*time.Second)
826+
deferdialCancel()
826827
apiAgent,err:=db2sdk.WorkspaceAgent(
827828
api.DERPMap(),
828829
*api.TailnetCoordinator.Load(),
@@ -857,8 +858,7 @@ func (api *API) watchWorkspaceAgentContainers(rw http.ResponseWriter, r *http.Re
857858
}
858859
deferrelease()
859860

860-
watcherLogger:=api.Logger.Named("agent_container_watcher").With(slog.F("agent_id",workspaceAgent.ID))
861-
containersCh,closer,err:=agentConn.WatchContainers(ctx,watcherLogger)
861+
containersCh,closer,err:=agentConn.WatchContainers(ctx,logger)
862862
iferr!=nil {
863863
httpapi.Write(ctx,rw,http.StatusInternalServerError, codersdk.Response{
864864
Message:"Internal error watching agent's containers.",
@@ -877,14 +877,17 @@ func (api *API) watchWorkspaceAgentContainers(rw http.ResponseWriter, r *http.Re
877877
return
878878
}
879879

880+
ctx,cancel:=context.WithCancel(r.Context())
881+
defercancel()
882+
880883
// Here we close the websocket for reading, so that the websocket library will handle pings and
881884
// close frames.
882885
_=conn.CloseRead(context.Background())
883886

884887
ctx,wsNetConn:=codersdk.WebsocketNetConn(ctx,conn,websocket.MessageText)
885888
deferwsNetConn.Close()
886889

887-
gohttpapi.Heartbeat(ctx,conn)
890+
gohttpapi.HeartbeatClose(ctx,logger,cancel,conn)
888891

889892
encoder:=json.NewEncoder(wsNetConn)
890893

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp