Skip to content

fix: Avoid use of r.Context() after r.Hijack() #1978

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 3, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: Use of r.Context() in workspaceAgentDial
  • Loading branch information
mafredri committed Jun 3, 2022
commit 0a354b6c63b38b0b9b0ec7709c36687fe2aff1bd
11 changes: 6 additions & 5 deletions coderd/workspaceagents.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,18 @@ func (api *API) workspaceAgentDial(rw http.ResponseWriter, r *http.Request) {
})
return
}
defer func() {
_ = conn.Close(websocket.StatusNormalClosure, "")
}()

ctx, wsNetConn := websocketNetConn(r.Context(), conn, websocket.MessageBinary)
defer wsNetConn.Close() // Also closes conn.

config := yamux.DefaultConfig()
config.LogOutput = io.Discard
session, err := yamux.Server(websocket.NetConn(r.Context(), conn, websocket.MessageBinary), config)
session, err := yamux.Server(wsNetConn, config)
if err != nil {
_ = conn.Close(websocket.StatusAbnormalClosure, err.Error())
return
}
err = peerbroker.ProxyListen(r.Context(), session, peerbroker.ProxyOptions{
err = peerbroker.ProxyListen(ctx, session, peerbroker.ProxyOptions{
ChannelID: workspaceAgent.ID.String(),
Logger: api.Logger.Named("peerbroker-proxy-dial"),
Pubsub: api.Pubsub,
Expand Down