Skip to content

Commit f3db876

Browse files
fix: stop reading closed channel for /watch devcontainers endpoint (coder#19373) (coder#20095)
Fixes coder#19372
1 parent a9bdbdb commit f3db876

File tree

5 files changed

+251
-151
lines changed

5 files changed

+251
-151
lines changed

agent/agentcontainers/api.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,11 @@ func (api *API) broadcastUpdatesLocked() {
763763
func (api *API) watchContainers(rw http.ResponseWriter, r *http.Request) {
764764
ctx := r.Context()
765765

766-
conn, err := websocket.Accept(rw, r, nil)
766+
conn, err := websocket.Accept(rw, r, &websocket.AcceptOptions{
767+
// We want `NoContextTakeover` compression to balance improving
768+
// bandwidth cost/latency with minimal memory usage overhead.
769+
CompressionMode: websocket.CompressionNoContextTakeover,
770+
})
767771
if err != nil {
768772
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
769773
Message: "Failed to upgrade connection to websocket.",

coderd/workspaceagents.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,11 @@ func (api *API) watchWorkspaceAgentContainers(rw http.ResponseWriter, r *http.Re
899899
case <-ctx.Done():
900900
return
901901

902-
case containers := <-containersCh:
902+
case containers, ok := <-containersCh:
903+
if !ok {
904+
return
905+
}
906+
903907
if err := encoder.Encode(containers); err != nil {
904908
api.Logger.Error(ctx, "encode containers", slog.Error(err))
905909
return

0 commit comments

Comments
 (0)