From 454aee86997aeb75f06c6cecbc15c3355b5e8d30 Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Wed, 25 Oct 2023 05:39:27 -0700 Subject: [PATCH] ws_js.go: Disable read limit on -1 Whoops, updates #254 and closes #410 --- ws_js.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ws_js.go b/ws_js.go index cf119da7..77d0d80f 100644 --- a/ws_js.go +++ b/ws_js.go @@ -42,7 +42,7 @@ const ( // Conn provides a wrapper around the browser WebSocket API. type Conn struct { noCopy noCopy - ws wsjs.WebSocket + ws wsjs.WebSocket // read limit for a message in bytes. msgReadLimit xsync.Int64 @@ -138,7 +138,8 @@ func (c *Conn) Read(ctx context.Context) (MessageType, []byte, error) { if err != nil { return 0, nil, fmt.Errorf("failed to read: %w", err) } - if int64(len(p)) > c.msgReadLimit.Load() { + readLimit := c.msgReadLimit.Load() + if readLimit >= 0 && int64(len(p)) > readLimit { err := fmt.Errorf("read limited at %v bytes", c.msgReadLimit.Load()) c.Close(StatusMessageTooBig, err.Error()) return 0, nil, err