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

Commitf61c2ad

Browse files
committed
fix: Use of r.Context() in workspaceAgentPTY
1 parent0b0aac0 commitf61c2ad

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

‎coderd/workspaceagents.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -376,12 +376,12 @@ func (api *API) workspaceAgentPTY(rw http.ResponseWriter, r *http.Request) {
376376
})
377377
return
378378
}
379-
deferfunc() {
380-
_=conn.Close(websocket.StatusNormalClosure,"ended")
381-
}()
379+
382380
// Accept text connections, because it's more developer friendly.
383-
wsNetConn:=websocket.NetConn(r.Context(),conn,websocket.MessageBinary)
384-
agentConn,err:=api.dialWorkspaceAgent(r,workspaceAgent.ID)
381+
ctx,wsNetConn:=websocketNetConn(r.Context(),conn,websocket.MessageBinary)
382+
deferwsNetConn.Close()// Also closes conn.
383+
384+
agentConn,err:=api.dialWorkspaceAgent(ctx,r,workspaceAgent.ID)
385385
iferr!=nil {
386386
_=conn.Close(websocket.StatusInternalError,httpapi.WebsocketCloseSprintf("dial workspace agent: %s",err))
387387
return
@@ -400,11 +400,13 @@ func (api *API) workspaceAgentPTY(rw http.ResponseWriter, r *http.Request) {
400400
_,_=io.Copy(ptNetConn,wsNetConn)
401401
}
402402

403-
// dialWorkspaceAgent connects to a workspace agent by ID.
404-
func (api*API)dialWorkspaceAgent(r*http.Request,agentID uuid.UUID) (*agent.Conn,error) {
403+
// dialWorkspaceAgent connects to a workspace agent by ID. Only rely on
404+
// r.Context() for cancellation if it's use is safe or r.Hijack() has
405+
// not been performed.
406+
func (api*API)dialWorkspaceAgent(ctx context.Context,r*http.Request,agentID uuid.UUID) (*agent.Conn,error) {
405407
client,server:=provisionersdk.TransportPipe()
406408
gofunc() {
407-
_=peerbroker.ProxyListen(r.Context(),server, peerbroker.ProxyOptions{
409+
_=peerbroker.ProxyListen(ctx,server, peerbroker.ProxyOptions{
408410
ChannelID:agentID.String(),
409411
Logger:api.Logger.Named("peerbroker-proxy-dial"),
410412
Pubsub:api.Pubsub,
@@ -414,7 +416,7 @@ func (api *API) dialWorkspaceAgent(r *http.Request, agentID uuid.UUID) (*agent.C
414416
}()
415417

416418
peerClient:=proto.NewDRPCPeerBrokerClient(provisionersdk.Conn(client))
417-
stream,err:=peerClient.NegotiateConnection(r.Context())
419+
stream,err:=peerClient.NegotiateConnection(ctx)
418420
iferr!=nil {
419421
returnnil,xerrors.Errorf("negotiate: %w",err)
420422
}
@@ -426,7 +428,7 @@ func (api *API) dialWorkspaceAgent(r *http.Request, agentID uuid.UUID) (*agent.C
426428
options.SettingEngine.SetICEProxyDialer(turnconn.ProxyDialer(func() (c net.Conn,errerror) {
427429
clientPipe,serverPipe:=net.Pipe()
428430
gofunc() {
429-
<-r.Context().Done()
431+
<-ctx.Done()
430432
_=clientPipe.Close()
431433
_=serverPipe.Close()
432434
}()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp