Skip to content

Commit

Permalink
fix: check for a cancelled context for websocket connection (#116)
Browse files Browse the repository at this point in the history
This change adds a check for a cancelled context to the websocket
connection handler. This aims to avoid the connnection handler getting
stuck if the received context has been cancelled.
  • Loading branch information
Melraidin authored and rvagg committed Jul 4, 2024
1 parent e75dcdc commit e59e680
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1604,7 +1604,7 @@ func (h *BigCallTestServerHandler) Ch(ctx context.Context) (<-chan int, error) {
func TestBigResult(t *testing.T) {
if os.Getenv("I_HAVE_A_LOT_OF_MEMORY_AND_TIME") != "1" {
// needs ~40GB of memory and ~4 minutes to run
t.Skip("skipping test due to requiced resources, set I_HAVE_A_LOT_OF_MEMORY_AND_TIME=1 to run")
t.Skip("skipping test due to required resources, set I_HAVE_A_LOT_OF_MEMORY_AND_TIME=1 to run")
}

// setup server
Expand Down
3 changes: 3 additions & 0 deletions websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,9 @@ func (c *wsConn) handleWsConn(ctx context.Context) {
if !c.tryReconnect(ctx) {
return // failed to reconnect
}
case <-ctx.Done():
log.Debugw("context cancelled", "error", ctx.Err(), "lastAction", action, "time", time.Since(start))
return
case req := <-c.requests:
action = fmt.Sprintf("send-request(%s,%v)", req.req.Method, req.req.ID)

Expand Down

0 comments on commit e59e680

Please sign in to comment.