Skip to content

Commit

Permalink
ws_js.go: Disable read limit on -1
Browse files Browse the repository at this point in the history
Whoops, updates #254 and closes #410
  • Loading branch information
nhooyr committed Oct 25, 2023
1 parent b4e4f4f commit 454aee8
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions ws_js.go
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 454aee8

Please sign in to comment.