Skip to content

Commit b955c5f

Browse files
authored
fix: avoid agent runLoop exiting due to ws ping (#8852)
1 parent f48e8dc commit b955c5f

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

agent/agent.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,9 @@ func (a *agent) runLoop(ctx context.Context) {
236236
if err == nil {
237237
continue
238238
}
239-
if errors.Is(err, context.Canceled) {
239+
if ctx.Err() != nil {
240+
// Context canceled errors may come from websocket pings, so we
241+
// don't want to use `errors.Is(err, context.Canceled)` here.
240242
return
241243
}
242244
if a.isClosed() {

codersdk/agentsdk/agentsdk.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ func (c *Client) DERPMapUpdates(ctx context.Context) (<-chan DERPMapUpdate, io.C
204204
defer close(updates)
205205
defer close(updatesClosed)
206206
defer cancelFunc()
207-
defer conn.Close(websocket.StatusGoingAway, "Listen closed")
207+
defer conn.Close(websocket.StatusGoingAway, "DERPMapUpdates closed")
208208
for {
209209
var update DERPMapUpdate
210210
err := dec.Decode(&update.DERPMap)
@@ -240,7 +240,7 @@ func (c *Client) DERPMapUpdates(ctx context.Context) (<-chan DERPMapUpdate, io.C
240240
closeFunc: func() error {
241241
cancelFunc()
242242
<-pingClosed
243-
_ = conn.Close(websocket.StatusGoingAway, "Listen closed")
243+
_ = conn.Close(websocket.StatusGoingAway, "DERPMapUpdates closed")
244244
<-updatesClosed
245245
return nil
246246
},

0 commit comments

Comments
 (0)