-
Notifications
You must be signed in to change notification settings - Fork 708
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: protocol parsing errors with ws compression and pongs #1790
Conversation
Amazing find @rsafonseca, thank you. My only concern is the added allocations - maybe we could only copy the slice if it's necessary? What I mean is - if we already create a new byte slice when decompressing, this one does not have to be cloned again when appending to |
Yeah, i considered that, but when i ran the benchmark i didn't see any noticeable difference and just wanted to keep it simple for getting the issue fixed. The memory allocation should be quickly released though as soon as drainPendingMessages runs. |
I've pushed a simple change for this, WDYT @piotrpio ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks nice and simple enough, I see no reason not to avoid those allocations 🙂
LGTM, but it would be good if @wallyqs could take a look as well.
Thanks for the contribution!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
qq, when do you expect a new tag version that includes it? :) |
@rsafonseca most probably second week of February |
Fixes: #1783
This PR addresses a problem that happens when using WS compression and receiving PONGs from the server along with other compressed messages.
The byte slices added to websocketReader.pending are memory references to the original buffer, so when the buffer is re-written in websocketReader.drainPending([]byte) the value for the pending PONG message takes a value that is part of the re-written bytes in the buffer.
This only happens with compression, because the size of the messages in the buffer changes, and only happens when receiving PONG messages, because the value for the regular messages is a new []byte generated after decompression, and not a memory reference to a sub-slice of the original buffer