IBM / fluent-forward-go

A high-performance Go client for Fluentd and Fluent Bit

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[πŸ› Bug] WebSocket Send funciton can send malformed frames

jchauvin opened this issue Β· comments

The Send function in fluent/client/ws_client.go for Websocket clients can potentially send partial malformed messages that will result in the receiver getting only a portion of the message. These will then manifest as Unexpected EOF errors on the receiver or MessagePack (msgp) trying to unpack an incorrect type - msgp: attempted to decode type. It should be expecting a 3 element array, however if in this situation a portion of the message is sent without the header. This is typically the result of a large message being sent, since the EncodeMsg function of MessagePack has a 2k buffer which will cause these issues.

Actual result
After sending a message with the ws_client.go Send function, we get Unexpected EOF or msgp: attempted to decode type errors on the listner end. We are not sending the entire message in one frame and it confuses the listener.

Expected result
The entire expected Byte stream should be received at the listener end, without any data loss and in the correct format

Additional Information

We've already tested a bug fix for this and simply need to implement it here with valid test cases. The fix is to declare a byte buffer, encoding directly to it, and then using the session.Connection.Write function to send it on the wire in it's entirety.

Currently we are using return msgp.Encode(session.Connection, e) and this will, in certain situations, break up the network writes by issuing flushes and writes when the MessagePack buffer doesn't have space for our message

Issue is fixed. Closing.