Skip to content

Commit 457d156

Browse files
committed
Fix WebSocket not closing
1 parent 299d30c commit 457d156

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-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/workspaceagents.go

Lines changed: 6 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,10 +296,12 @@ 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
}
303307
}
@@ -423,6 +427,7 @@ func (c *Client) AgentReportStats(
423427
var req AgentStatsReportRequest
424428
err := wsjson.Read(ctx, conn, &req)
425429
if err != nil {
430+
_ = conn.Close(websocket.StatusAbnormalClosure, "")
426431
return err
427432
}
428433

@@ -436,6 +441,7 @@ func (c *Client) AgentReportStats(
436441

437442
err = wsjson.Write(ctx, conn, resp)
438443
if err != nil {
444+
_ = conn.Close(websocket.StatusAbnormalClosure, "")
439445
return err
440446
}
441447
}

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