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

Commite90a0c0

Browse files
committed
fix: Use of r.Context() in workspaceAgentPTY
1 parente0fb30c commite90a0c0

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
@@ -387,12 +387,12 @@ func (api *API) workspaceAgentPTY(rw http.ResponseWriter, r *http.Request) {
387387
})
388388
return
389389
}
390-
deferfunc() {
391-
_=conn.Close(websocket.StatusNormalClosure,"ended")
392-
}()
390+
393391
// Accept text connections, because it's more developer friendly.
394-
wsNetConn:=websocket.NetConn(r.Context(),conn,websocket.MessageBinary)
395-
agentConn,err:=api.dialWorkspaceAgent(r,workspaceAgent.ID)
392+
ctx,wsNetConn:=websocketNetConn(r.Context(),conn,websocket.MessageBinary)
393+
deferwsNetConn.Close()// Also closes conn.
394+
395+
agentConn,err:=api.dialWorkspaceAgent(ctx,r,workspaceAgent.ID)
396396
iferr!=nil {
397397
_=conn.Close(websocket.StatusInternalError,httpapi.WebsocketCloseSprintf("dial workspace agent: %s",err))
398398
return
@@ -411,11 +411,13 @@ func (api *API) workspaceAgentPTY(rw http.ResponseWriter, r *http.Request) {
411411
_,_=io.Copy(ptNetConn,wsNetConn)
412412
}
413413

414-
// dialWorkspaceAgent connects to a workspace agent by ID.
415-
func (api*API)dialWorkspaceAgent(r*http.Request,agentID uuid.UUID) (*agent.Conn,error) {
414+
// dialWorkspaceAgent connects to a workspace agent by ID. Only rely on
415+
// r.Context() for cancellation if it's use is safe or r.Hijack() has
416+
// not been performed.
417+
func (api*API)dialWorkspaceAgent(ctx context.Context,r*http.Request,agentID uuid.UUID) (*agent.Conn,error) {
416418
client,server:=provisionersdk.TransportPipe()
417419
gofunc() {
418-
_=peerbroker.ProxyListen(r.Context(),server, peerbroker.ProxyOptions{
420+
_=peerbroker.ProxyListen(ctx,server, peerbroker.ProxyOptions{
419421
ChannelID:agentID.String(),
420422
Logger:api.Logger.Named("peerbroker-proxy-dial"),
421423
Pubsub:api.Pubsub,
@@ -425,7 +427,7 @@ func (api *API) dialWorkspaceAgent(r *http.Request, agentID uuid.UUID) (*agent.C
425427
}()
426428

427429
peerClient:=proto.NewDRPCPeerBrokerClient(provisionersdk.Conn(client))
428-
stream,err:=peerClient.NegotiateConnection(r.Context())
430+
stream,err:=peerClient.NegotiateConnection(ctx)
429431
iferr!=nil {
430432
returnnil,xerrors.Errorf("negotiate: %w",err)
431433
}
@@ -437,7 +439,7 @@ func (api *API) dialWorkspaceAgent(r *http.Request, agentID uuid.UUID) (*agent.C
437439
options.SettingEngine.SetICEProxyDialer(turnconn.ProxyDialer(func() (c net.Conn,errerror) {
438440
clientPipe,serverPipe:=net.Pipe()
439441
gofunc() {
440-
<-r.Context().Done()
442+
<-ctx.Done()
441443
_=clientPipe.Close()
442444
_=serverPipe.Close()
443445
}()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp