Skip to content

Commit e59e680

Browse files
Melraidinrvagg
authored andcommitted
fix: check for a cancelled context for websocket connection (#116)
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.
1 parent e75dcdc commit e59e680

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

rpc_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1604,7 +1604,7 @@ func (h *BigCallTestServerHandler) Ch(ctx context.Context) (<-chan int, error) {
16041604
func TestBigResult(t *testing.T) {
16051605
if os.Getenv("I_HAVE_A_LOT_OF_MEMORY_AND_TIME") != "1" {
16061606
// needs ~40GB of memory and ~4 minutes to run
1607-
t.Skip("skipping test due to requiced resources, set I_HAVE_A_LOT_OF_MEMORY_AND_TIME=1 to run")
1607+
t.Skip("skipping test due to required resources, set I_HAVE_A_LOT_OF_MEMORY_AND_TIME=1 to run")
16081608
}
16091609

16101610
// setup server

websocket.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,9 @@ func (c *wsConn) handleWsConn(ctx context.Context) {
790790
if !c.tryReconnect(ctx) {
791791
return // failed to reconnect
792792
}
793+
case <-ctx.Done():
794+
log.Debugw("context cancelled", "error", ctx.Err(), "lastAction", action, "time", time.Since(start))
795+
return
793796
case req := <-c.requests:
794797
action = fmt.Sprintf("send-request(%s,%v)", req.req.Method, req.req.ID)
795798

0 commit comments

Comments
 (0)