Skip to content

Commit 4a69c0b

Browse files
committed
fix data race
1 parent e9fb747 commit 4a69c0b

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

internal/js/modules/k6/experimental/websockets/websockets.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -501,18 +501,25 @@ func (w *webSocket) readPump(wg *sync.WaitGroup) {
501501
}
502502

503503
var closeErr *websocket.CloseError
504+
var code int
505+
var reason string
504506
if errors.As(err, &closeErr) {
505-
w.closeCode = closeErr.Code
506-
w.closeReason = closeErr.Text
507+
code = closeErr.Code
508+
reason = closeErr.Text
507509
}
508510

509511
if !websocket.IsUnexpectedCloseError(err, websocket.CloseNormalClosure, websocket.CloseGoingAway) {
510512
err = nil
511513
}
512514

515+
errLocal := err
513516
w.tq.Queue(func() error {
517+
if code != 0 {
518+
w.closeCode = code
519+
w.closeReason = reason
520+
}
514521
_ = w.conn.Close()
515-
return w.connectionClosedWithError(err)
522+
return w.connectionClosedWithError(errLocal)
516523
})
517524
return
518525
}

0 commit comments

Comments
 (0)