Skip to content

Commit 87f3c20

Browse files
committed
Fix WebSocket not closing
1 parent 299d30c commit 87f3c20

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

agent/agent_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ func setupSSHCommand(t *testing.T, beforeArgs []string, afterArgs []string) *exe
522522
return
523523
}
524524
ssh, err := agentConn.SSH()
525-
if !assert.NoError(t, err) {
525+
if err != nil {
526526
_ = conn.Close()
527527
return
528528
}

codersdk/provisionerdaemons.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ func (c *Client) provisionerJobLogsAfter(ctx context.Context, path string, after
135135
decoder := json.NewDecoder(websocket.NetConn(ctx, conn, websocket.MessageText))
136136
go func() {
137137
defer close(logs)
138+
defer conn.Close(websocket.StatusGoingAway, "")
138139
var log ProvisionerJobLog
139140
for {
140141
err = decoder.Decode(&log)

codersdk/workspaceagents.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,12 @@ func (c *Client) DialWorkspaceAgentTailnet(ctx context.Context, logger slog.Logg
281281
CompressionMode: websocket.CompressionDisabled,
282282
})
283283
if errors.Is(err, context.Canceled) {
284+
_ = ws.Close(websocket.StatusAbnormalClosure, "")
284285
return
285286
}
286287
if err != nil {
287288
logger.Debug(ctx, "failed to dial", slog.Error(err))
289+
_ = ws.Close(websocket.StatusAbnormalClosure, "")
288290
continue
289291
}
290292
sendNode, errChan := tailnet.ServeCoordinator(websocket.NetConn(ctx, ws, websocket.MessageBinary), func(node []*tailnet.Node) error {
@@ -294,12 +296,15 @@ func (c *Client) DialWorkspaceAgentTailnet(ctx context.Context, logger slog.Logg
294296
logger.Debug(ctx, "serving coordinator")
295297
err = <-errChan
296298
if errors.Is(err, context.Canceled) {
299+
_ = ws.Close(websocket.StatusAbnormalClosure, "")
297300
return
298301
}
299302
if err != nil {
300303
logger.Debug(ctx, "error serving coordinator", slog.Error(err))
304+
_ = ws.Close(websocket.StatusAbnormalClosure, "")
301305
continue
302306
}
307+
_ = ws.Close(websocket.StatusAbnormalClosure, "")
303308
}
304309
}()
305310
return &agent.Conn{
@@ -423,6 +428,7 @@ func (c *Client) AgentReportStats(
423428
var req AgentStatsReportRequest
424429
err := wsjson.Read(ctx, conn, &req)
425430
if err != nil {
431+
_ = conn.Close(websocket.StatusAbnormalClosure, "")
426432
return err
427433
}
428434

@@ -436,6 +442,7 @@ func (c *Client) AgentReportStats(
436442

437443
err = wsjson.Write(ctx, conn, resp)
438444
if err != nil {
445+
_ = conn.Close(websocket.StatusAbnormalClosure, "")
439446
return err
440447
}
441448
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy