Skip to content

Commit a1b12a2

Browse files
committed
Explain why we have r.Limit
Updates #46
1 parent bac4153 commit a1b12a2

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

websocket.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,14 @@ func (r *MessageReader) SetContext(ctx context.Context) {
501501
}
502502

503503
// Limit limits the number of bytes read by the reader.
504+
//
505+
// Why not use io.LimitReader? io.LimitReader returns a io.EOF
506+
// after the limit bytes which means its not possible to tell
507+
// whether the message has been read or a limit has been hit.
508+
// This results in unclear error and log messages.
509+
// This function will cause the connection to be closed if the limit is hit
510+
// with a close reason explaining the error and also an error
511+
// indicating the limit was hit.
504512
func (r *MessageReader) Limit(bytes int) {
505513
r.limit = bytes
506514
}

0 commit comments

Comments
 (0)