Harden frame processing on large data#69125
Open
uranusjr wants to merge 1 commit into
Open
Conversation
Previously, frame encoding and decoding are done against an in-memory byte array. This is simple, but may cause issues with very large amount of data, since the frame protocol allows 2^32 bytes of data per frame with the potential to clog the entire JVM. This uses the MessagePack library's MessageBuffer helper to encode to and decode from a MessagePack message into multiple lazy buffers, converting each buffer to a byte array separately on demand to reduce peak memory usage. I also cleaned up some abstractions since they are already pretty empty prior to this change.
phanikumv
reviewed
Jun 30, 2026
Comment on lines
+109
to
+118
| try { | ||
| Frame.decode(ChannelFrameInput(reader, declaredLength)) | ||
| } catch (e: Exception) { | ||
| logger.error( | ||
| "Failed to read or decode frame", | ||
| mapOf("length" to declaredLength, "exception" to e), | ||
| ) | ||
| shutDownRequested = true | ||
| return | ||
| } |
Contributor
There was a problem hiding this comment.
Suggested change
| try { | |
| Frame.decode(ChannelFrameInput(reader, declaredLength)) | |
| } catch (e: Exception) { | |
| logger.error( | |
| "Failed to read or decode frame", | |
| mapOf("length" to declaredLength, "exception" to e), | |
| ) | |
| shutDownRequested = true | |
| return | |
| } | |
| try { | |
| Frame.decode(ChannelFrameInput(reader, declaredLength)) | |
| } catch (e: CancellationException) { | |
| throw e | |
| } catch (e: Exception) { | |
| logger.error( | |
| "Failed to read or decode frame", | |
| mapOf("length" to declaredLength, "exception" to e), | |
| ) | |
| shutDownRequested = true | |
| return | |
| } |
Contributor
There was a problem hiding this comment.
(needs import kotlinx.coroutines.CancellationException)
catch (e: Exception) also catches CancellationException, so a cancellation during decode becomes a clean shutdown instead of propagating. Minor and
pre-existing in this file, but the new broad catch makes it worth rethrowing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Previously, frame encoding and decoding are done against an in-memory byte array. This is simple, but may cause issues with very large amount of data, since the frame protocol allows 2^32 bytes of data per frame with the potential to clog the entire JVM.
This uses the MessagePack library's MessageBuffer helper to encode to and decode from a MessagePack message into multiple lazy buffers, converting each buffer to a byte array separately on demand to reduce peak memory usage.
I also cleaned up some abstractions since they are already pretty empty prior to this change.