Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
nhooyr committed Oct 25, 2023
2 parents b4e4f4f + 454aee8 commit e2016ac
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions ws_js.go
Original file line number Diff line number Diff line change
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 e2016ac

Please sign in to comment.