Skip to content

Codec-compression: Add backpressure decompression handlers - #17161

Open
yawkat wants to merge 15 commits into
4.2from
pr-16743-backpressure-decompression
Open

yawkat wants to merge 15 commits into
4.2from
pr-16743-backpressure-decompression

Conversation

@yawkat

@yawkat yawkat commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Motivation:

The decompressor API migration in #15667 is being split into smaller, independently reviewable changes as tracked by #16743. The core API and decompressor implementations are available on 4.2, but the generic backpressure-aware handler infrastructure is not.

Modification:

  • Add BackpressureGauge, AbstractBackpressureDecompressionHandler, and BackpressureDecompressionHandler from New decompressor API #15667.
  • Preserve decompressor state and buffer ownership across manual reads, failures, end-of-input, and reentrant handler removal.
  • Bound manual reads that consume compressed input without producing output.
  • Add focused backpressure and read-complete tests.
  • Run the existing FastLZ, Bzip2, Snappy, Brotli, JDK zlib, LZ4, LZF, and Zstd decoder/integration suites through the new handler.
  • Keep the new APIs marked unstable while the migration is in progress.

Result:

Pull-based decompressors can be installed as channel handlers with bounded manual-read output and read-complete propagation. Existing 4.2 decompressor implementations are covered through the handler without adding HTTP/1.1, HTTP/2, or additional format work.

Verification:

./mvnw -B -ntp -pl codec-compression -am verify -Dcheckstyle.skip=false

All 11 reactor projects passed. codec-compression ran 700 tests with no failures or errors, and Checkstyle completed successfully. The nine newly added algorithm handler classes ran 93 focused tests with no failures, errors, or skips.

Part of #16743.

yawkat and others added 5 commits July 28, 2026 08:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR ports the generic backpressure-aware decompression handler infrastructure into codec-compression (as part of the staged decompressor API migration), and routes existing format test suites through the new handler to validate behavior.

Changes:

  • Add BackpressureGauge, AbstractBackpressureDecompressionHandler, and BackpressureDecompressionHandler to support bounded, manual-read-aware decompression.
  • Add focused unit tests for backpressure/read-complete behavior and handler-removal edge cases.
  • Re-run existing FastLZ/Bzip2/Snappy decoder and integration tests through the new handler via thin adapter test classes.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
codec-compression/src/main/java/io/netty/handler/codec/compression/AbstractBackpressureDecompressionHandler.java New shared implementation for backpressure-aware decompression with manual-read support.
codec-compression/src/main/java/io/netty/handler/codec/compression/BackpressureDecompressionHandler.java Concrete ChannelHandler adapter that wires a Decompressor into the shared backpressure logic.
codec-compression/src/main/java/io/netty/handler/codec/compression/BackpressureGauge.java New backpressure accounting/config component (messages/bytes per read).
codec-compression/src/test/java/io/netty/handler/codec/compression/BackpressureDecompressionHandlerTest.java New focused tests for backpressure, end-of-input, message replay, and re-entrant removal.
codec-compression/src/test/java/io/netty/handler/codec/compression/Bzip2DecoderTest.java Adjust teardown/exception handling path for tests that expect failures.
codec-compression/src/test/java/io/netty/handler/codec/compression/Bzip2DecompressorHandlerIntegrationTest.java Runs existing Bzip2 integration suite through BackpressureDecompressionHandler.
codec-compression/src/test/java/io/netty/handler/codec/compression/Bzip2DecompressorHandlerTest.java Runs existing Bzip2 decoder tests through BackpressureDecompressionHandler.
codec-compression/src/test/java/io/netty/handler/codec/compression/FastLzDecompressorHandlerIntegrationTest.java Runs existing FastLZ integration suite through BackpressureDecompressionHandler.
codec-compression/src/test/java/io/netty/handler/codec/compression/SnappyDecompressorHandlerIntegrationTest.java Runs existing Snappy integration suite through BackpressureDecompressionHandler.
codec-compression/src/test/java/io/netty/handler/codec/compression/SnappyDecompressorHandlerJumboSizeIntegrationTest.java Runs existing Snappy jumbo-size integration suite through BackpressureDecompressionHandler.
codec-compression/src/test/java/io/netty/handler/codec/compression/SnappyFrameDecoderTest.java Refactors to allow swapping decoder implementation in derived tests.
codec-compression/src/test/java/io/netty/handler/codec/compression/SnappyFrameDecompressorHandlerTest.java Runs existing Snappy frame decoder tests through BackpressureDecompressionHandler.
Comments suppressed due to low confidence (3)

codec-compression/src/main/java/io/netty/handler/codec/compression/AbstractBackpressureDecompressionHandler.java:247

  • Same issue as above: after reading = true, this second guard-return (after computing decompressor status) can return without resetting reading to false if heldBack is changed reentrantly, leaving the handler in an inconsistent state.
        if (this.heldBack != heldBack) {
            return false;
        }

codec-compression/src/main/java/io/netty/handler/codec/compression/AbstractBackpressureDecompressionHandler.java:253

  • When heldBack is empty and no messages were written, the method returns false while reading is still true. This violates the method’s own assert !reading contract for future invocations and can prevent later channelRead(...) calls from resetting the per-read bookkeeping.
            if (heldBack.isEmpty() && !anyMessageWrittenSinceReadStart) {
                heldBack.recycle();
                return false;
            } else {

codec-compression/src/main/java/io/netty/handler/codec/compression/AbstractBackpressureDecompressionHandler.java:274

  • In the NEED_OUTPUT path, if no message was written, the method calls ctx.read() and returns false but leaves reading = true. Resetting reading before issuing a read avoids incorrectly treating the subsequent inbound read as re-entrant within the previous read cycle.
            ctx.read();
            return false;

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@yawkat yawkat left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Focused follow-up on manual-read accounting and trailing input handling. I did not raise the handler-removal or non-ByteBuf points; the latter is consistent with this handler's explicit ByteBuf-only contract despite differing from ByteToMessageDecoder pass-through behavior.

yawkat and others added 10 commits July 28, 2026 14:16
@testlens-app

testlens-app Bot commented Jul 28, 2026 •

Copy link
Copy Markdown

🔎 No tests executed 🔎

🏷️ Commit: 83524f1
▶️ Tests: 0 executed
⚪️ Checks: 19/19 completed


Learn more about TestLens at testlens.app/docs.

yawkat added a commit that referenced this pull request Sep 26, 2026
Motivation:

Most of this PR has been split out and merged to 4.2 (#16745, #17145-#17155),
and the backpressure handler is under review in #17161. The split versions
received review fixes that this branch does not have, which left the PR
conflicting with 4.2 in every decompressor.

Modification:

* Take the merged 4.2 decompressor implementations and the #17161 version of
  the backpressure handler infrastructure.
* Re-apply the remaining unmerged parts of this PR on top: HTTP/1.1
  HttpDecompressionHandler, HTTP/2 DecompressingFrameListener, their tests,
  and deprecation of the legacy decoders.
* Drop JZlib support (JZlibDecompressor, ZlibDecompressor base class,
  ZlibCodecFactory decompressor builder). HttpDecompressionHandler uses
  JdkZlibDecompressor directly.
* Restore BackpressureGauge.relieveBackpressure(long), which #17161 removed
  but DecompressingFrameListener needs for HTTP/2 flow-control credit.

Result:

The PR applies cleanly on 4.2 again and only carries the unmerged parts of
#16743.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants