Skip to content

Commit 4b6777d

Browse files
committed
fix: ensure wsproxy MultiAgent is closed when websocket dies
The `SingleTailnet` behavior only checked to see if the `MultiAgent` was closed, but the websocket error was not being propogated into the `MultiAgent`, causing it to never be swapped for a new working one.
1 parent 85ff030 commit 4b6777d

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

coderd/httpapi/websocket.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ func Heartbeat(ctx context.Context, conn *websocket.Conn) {
2626
}
2727
}
2828

29-
// Heartbeat loops to ping a WebSocket to keep it alive. It kills the connection
30-
// on ping failure.
29+
// Heartbeat loops to ping a WebSocket to keep it alive. It calls `exit` on ping
30+
// failure.
3131
func HeartbeatClose(ctx context.Context, exit func(), conn *websocket.Conn) {
32-
ticker := time.NewTicker(30 * time.Second)
32+
ticker := time.NewTicker(15 * time.Second)
3333
defer ticker.Stop()
3434

3535
for {

coderd/tailnet.go

+1
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ func (s *ServerTailnet) watchAgentUpdates() {
224224
nodes, ok := conn.NextUpdate(s.ctx)
225225
if !ok {
226226
if conn.IsClosed() && s.ctx.Err() == nil {
227+
s.logger.Warn(s.ctx, "multiagent closed, reinitializing")
227228
s.reinitCoordinator()
228229
continue
229230
}

enterprise/wsproxy/wsproxysdk/wsproxysdk.go

+5
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,11 @@ func (c *Client) DialCoordinator(ctx context.Context) (agpl.MultiAgentConn, erro
472472
OnRemove: func(agpl.Queue) { conn.Close(websocket.StatusGoingAway, "closed") },
473473
}).Init()
474474

475+
go func() {
476+
<-ctx.Done()
477+
ma.Close()
478+
}()
479+
475480
go func() {
476481
defer cancel()
477482
dec := json.NewDecoder(nc)

0 commit comments

Comments
 (0)