WebSocket13FrameEncoder should overrides encode instead of encodeAndClose #12780
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation:
The #12773 PR has fixed a memory leak from the WebSocket13FrameEncoder.encodeAndClose method, where the websocket frame to be encoded was not always closed properly.
Now, @amizurov has suggested to do a better fix by just letting the WebSocket13FrameEncoder override the encode method instead of the encodeAndClose. It give an autoclose for the input argument and don't need to do this manually, behaviour will be similar with 4.1.
However, care must be taken when the frame is itself appended to the "out" list of produced data. In 4.x, this was done using "data.retain", with the new Buffer API, the data can be added to the "out" list using "data.split".
Modification:
The WebSocket13FrameEncoder is now overriding the encode method instead of the encodeAndClose, and the frame message is not closed anymore at all (this is done by the encodeAndClose method from the superclass).
And when the frame message data has to be appended into the "out" list of produced encoded data, then it is done using "data.split"
Result:
The WebSocket13FrameEncoder class is simpler and don't have to close the frame data parameter.