Improve WebSocket compression internals and resource cleanup - #1173
Merged
Conversation
* Reuse 8 KiB buffers in the inflater and deflater flows. * Accumulate split frame data without repeatedly copying earlier chunks. * Handle extension parameters and custom WebSocket settings defensively. * Simplify extension header handling and align disabled compression defaults.
* Inject inflater and deflater creation per materialized flow instead of using mutable global test hooks. * Verify cleanup after completion, failure, cancellation, protocol errors, and incomplete frame or message state. * Ensure every created compression resource is released exactly once.
Use the 256 KiB default agreed during review of the initial WebSocket compression implementation. Keep the disabled settings baseline aligned with reference.conf.
Contributor
Author
|
I also pushed commit which increases the default WebSocket decompression limit from 64 KiB to 256 KiB, as agreed during the review of #1114 (comment). |
Member
|
lgtm |
pjfanning
approved these changes
Jul 23, 2026
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.
This is a follow-up to
that addresses review feedback and improves the WebSocket compression implementation without changing its public API or configuration.
The changes:
client_max_window_bitsandserver_max_window_bitsvalues.WebSocketSettingsimplementations without an unsafe cast.Sec-WebSocket-Extensionsheaders directly.reference.confdefault formax-allocation.InflaterandDeflateris released exactly once.Resource cleanup is tested for normal completion, upstream failure, downstream cancellation, protocol errors, and incomplete compression state.
The wire and stream semantics for incomplete compressed messages intentionally remain unchanged. This follows Netty’s compression-layer behavior: incomplete codec state is discarded during connection termination while its resources are released. Any future change to truncated-message handling should be designed as a general WebSocket framing change covering both compressed and uncompressed messages.
Testing
WebSocketServerSpecsbt applyCodeStylesbt checkCodeStylesbt +mimaReportBinaryIssuessbt validatePullRequestReferences