GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Inflate HTTP/1.1 gzip and deflate without an EmbeddedChannel by pavel-ptashyts · Pull Request #2357 · AsyncHttpClient/async-http-client Conversation
Contributor
Summary
Closes #2356.
CompatibilityThe gzip/deflate handling is a port of A differential test feeds Netty's Deliberate differences:
Known and left as is:
Tests
Mutation checks during development: breaking the cross-chunk header path, the removal/close guards, the Verification
Benchmark
Per response that is 1.6 to 9 us less CPU and 60 to 93% less allocation. The remaining ~1.2 KB/op is mostly ReviewReviewed per the two-reviewer loop used by the author's team: Codex
Round 7 nits not taken, with reasons: a 100-continue head without its Claude Code on behalf of Pavel Ptashyts 🤖 Generated with Claude Code
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsHttpContentDecompressor builds an EmbeddedChannel and a new Inflater for every compressed response, and its JdkZlibDecoder copies each direct input buffer onto the heap before inflating it. On a client that reads many small gzip responses this shows up as steady allocation and native zlib init/free on the event loop. Http1ContentDecompressor already lives in the pipeline of a single connection, so it now inflates gzip, x-gzip, deflate and x-deflate itself: one Inflater per wrapper for the life of the connection, reset between responses, fed the input buffer as it is. Header and trailer checks, concatenated members, zlib-or-raw detection and the quiet end of a truncated stream follow JdkZlibDecoder, and a differential test holds the output and errors to Netty's across many chunk splits. Other encodings still go through Netty. Claude Code on behalf of Pavel Ptashyts Co-Authored-By: Claude Opus 5.5 <[email protected]> An Inflater kept per connection pins zlib's native window on every idle pooled connection, so a client with thousands of keep-alive connections would hold that memory for nothing. Inflaters now live in a small per-event-loop pool between responses. A handler further on may remove this one while a decoded chunk is being forwarded; decoding now stops there instead of carrying on with state that was already handed back. Tests cover removal mid-chunk, close mid-response, a full response, encodings left to Netty alternating with gzip on one connection, composite input, the deflate limit and more read-request shapes. Claude Code on behalf of Pavel Ptashyts Co-Authored-By: Claude Opus 5.5 <[email protected]> Checking ctx.isRemoved() after forwarding decoded content only caught a handler further on removing this one. Any way of ending the response from that callback, such as closing the channel, should stop the decoding that made the call, so each dropped response now bumps a counter that the decoding loop checks. The forwarding threshold reads the same system property as Netty's JdkZlibDecoder, and the differential test now also holds the number of decoded parts to Netty's. New tests cover the per-thread inflater pool and its cap, reuse of an inflater handed back by a removal, a close from a handler further on, and read requests for a read that mixes Netty's messages with this handler's, including a failed body. Claude Code on behalf of Pavel Ptashyts Co-Authored-By: Claude Opus 5.5 <[email protected]> Netty queues channelInactive, so a handler further on that closes the channel while decoded content is forwarded did not end the response: the rest of the body was still inflated and forwarded. The response is now abandoned when the channel went inactive during the forward. A channel that was already inactive when the message arrived is left alone, because HttpClientCodec ends a body without a length from channelInactive and that last part must still decode. A buffer that cannot grow fails with Netty's DecompressionException rather than an IndexOutOfBoundsException. Tests add a body ending with the connection, Transfer-Encoding gzip, an empty body, read-only input, and the inflater going back to the pool on close and removal. Claude Code on behalf of Pavel Ptashyts Co-Authored-By: Claude Opus 5.5 <[email protected]> ZlibDecoder.prepareDecompressBuffer grows the output buffer after every unfinished inflate step, so an allocator that caps heap buffers fails there. Growing only at the start of the next step let a capped buffer pass where Netty throws; the growth now happens at the same point. A channel closed while the response head is forwarded now drops the body already queued behind the head in the same read. The class notes that gzip and deflate no longer reach newContentDecoder and do not follow io.netty.noJdkZlibDecoder. Tests check that every input buffer is released, add pooled direct input and a capped allocator. Claude Code on behalf of Pavel Ptashyts Co-Authored-By: Claude Opus 5.5 <[email protected]> The pool tests now run on FastThreadLocalThreads, which is what Netty event loops are, so they take the same thread-local path as production, and a test checks that FastThreadLocal.removeAll() drops the idle inflaters. Another checks that the size limit counts every member of a concatenated gzip body together. The two places that fail a response share one helper, a guard that could never be false is gone, and a comment says why the inflater may keep pointing at an input buffer after it is released. Claude Code on behalf of Pavel Ptashyts Co-Authored-By: Claude Opus 5.5 <[email protected]> The removeAll() test only showed that the pool was dropped: asking for the pool again creates an empty one, so it passed even without the end() calls in onRemoval. Tests now reach the pool itself and check that the pooled inflater was ended. A message that is not HttpContent while a response is being inflated now goes to HttpContentDecoder instead of failing a cast. Closes AsyncHttpClient#2356 Claude Code on behalf of Pavel Ptashyts Co-Authored-By: Claude Opus 5.5 <[email protected]> An ended Inflater throws NullPointerException on JDK 11 to 21 and IllegalStateException on JDK 25, which failed the pool cleanup test on every JDK 25 CI job. An open inflater with no input throws nothing, so any RuntimeException still shows that the pooled inflater was ended. Claude Code on behalf of Pavel Ptashyts Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Contributor
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
14 tasks done
Contributor
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
hyperxpro
approved these changes
Uh oh!
There was an error while loading. Please reload this page.
4 tasks done
hyperxpro
pushed a commit
that referenced
this pull request
…ty 4.2.19 does (#2366) ## Summary - `main` fails `Http1ContentDecompressorTest.aBufferThatCannotGrowFailsLikeNetty` on every platform and JDK since #2357 and #2364 (Netty 4.2.19) were both merged. - Netty 4.2.19 includes netty/netty#17692: `ZlibDecoder` fails with "Decompression buffer has reached maximum size" only once the buffer cannot grow and is also full. The HTTP/1.1 inflate loop from #2357 copies the check from before that change. - Add the same condition to the loop, and let the test compare both cases with Netty. ## Problem The inflate loop grows its output buffer after every unfinished step, as `ZlibDecoder.prepareDecompressBuffer` does, so that a buffer that cannot grow fails at the same point as with Netty. Up to 4.2.18, Netty failed as soon as `ensureWritable(preferredSize, true)` returned 1, even if the buffer still had room. Since 4.2.19 it keeps inflating into the space that is left and fails only once nothing is writable. `aBufferThatCannotGrowFailsLikeNetty` feeds a flushed raw deflate stream of 900 random bytes into a buffer capped at 1024 bytes. Netty 4.2.19 decodes it; the loop still failed it, so the test's comparison fails. The "Build PR" run on `b9dbb212a` failed on all 12 test jobs with this test alone. ## Change - `Http1ContentDecompressor`: fail only if `ensureWritable(...) == 1 && !decompressed.isWritable()`, as `ZlibDecoder` does now. - `aBufferThatCannotGrowFailsLikeNetty` compares two cases with Netty: output that fits into the capped buffer is decoded, and output that overflows it (64 KiB of zeros) fails with Netty's message. Both still check that the inputs are released. The test from #2357 caught this; thanks @pavel-ptashyts. ## AI disclosure Claude Code on behalf of Matthias Kurz. The commit includes `Co-Authored-By` per `AGENTS.md`. ## Test plan - [x] On `main` (`b9dbb212a`), JDK 11: `aBufferThatCannotGrowFailsLikeNetty` fails in 3 of 3 runs, as in CI. - [x] With the change, `Http1ContentDecompressorTest` passes: 28 tests, including its comparisons with Netty over more than 300 scenarios. - [x] Without the code change, the new test fails in the "output fits" case, with the error `main` shows; the "output overflows" case fails the same way in both decoders. - [x] `./mvnw -B -ntp -Dgpg.skip=true clean verify` on JDK 11: 1,819 tests, 0 failures, 0 errors, 11 skipped; Revapi passed. No test-skipping flags were used. Co-authored-by: Claude Opus 5.5 <[email protected]>
mkurz
added a commit
to mkurz/async-http-client
that referenced
this pull request
Netty's HttpContentDecompressor, and the inflate loop that replaces it for gzip and deflate since AsyncHttpClient#2357, inflate each chunk completely as soon as it is read. Suspending a response through ResponseBodyControl stops further socket reads but not that, so one read of a highly compressible body still became tens of megabytes of body parts nobody had asked for. Check before each part whether the response is suspended. If it is, keep the input the inflater has not used, and whether it still holds output, together with every message that arrives after it, and inflate it on the next read request, such as the one resume() issues, before the read is passed on. To see read requests, the handler also implements ChannelOutboundHandler and passes every other outbound event through; its superclass and constructor stay as they are. A held chunk is retained, not copied, since the inflater may still point into it. Parts are cut where JdkZlibDecoder cuts them, but never past 64 KiB, so that a suspension takes effect within one part even when a large chunk inflates at once: each inflate() call is capped at what is left of a part, which also keeps a forwarding threshold of 0 making progress. The end of a fully inflated body still reaches a suspended response, as for an unencoded body, and a channel that closes while input is held hands the rest on at once. The differential tests against Netty now expect more parts where Netty hands on parts larger than 64 KiB. New unit tests cover suspension, removal, closure and the limit, a direct or pooled direct chunk paused mid-way, and output held without input; a fresh JVM checks a forwarding threshold of 0; the integration tests are those from before the rebuild. Claude Code on behalf of Matthias Kurz Co-Authored-By: Claude Opus 5.5 <[email protected]>
hyperxpro
added a commit
that referenced
this pull request
## Summary - While an HTTP/1.1 response is suspended through `ResponseBodyControl`, stop decompressing its body, for the content codings AHC decompresses: gzip, deflate, br, zstd and snappy. Body parts are at most 64 KiB, so a handler that suspends after each part receives one part per `resume()`. - Rebuilt on the inflate loop of #2357. `Http1ContentDecompressor` keeps its superclass and constructor, and also implements `ChannelOutboundHandler` to see read requests. Revapi needs no entries. - br, zstd and snappy are decompressed on demand too, with Netty's pull-based `Decompressor`, in a class of their own. Only these codings use that API, which Netty added in 4.2.17; without it they go to Netty's own decoders, as before. - A body that is being drained is no longer decompressed, and a failed decoder result on the last chunk is kept, for these content codings. - HTTP/2 decompression is unchanged; see below. The replay fix that used to be part of this pull request is now #2367. ## Problem Suspending a response stops further socket reads, but Netty's `HttpContentDecompressor`, and the inflate loop that replaces it for gzip and deflate since #2357, decompress every chunk completely as soon as it is read. So one socket read of a highly compressible body still became many parts that nobody had asked for. For example, one 64 KiB read of gzipped zeros (about 1032:1) becomes some 67 MB of body parts for a handler that has suspended the response. Only `maxDecompressedResponseSize` (256 MiB by default) bounds it. With 64 MiB of gzipped zeros and a handler that suspends inside each body callback, `main` before #2357 delivered 1,955,380 bytes in 30 more parts past the suspending part, and then up to 33,713,376 bytes per resume. This branch without its suspension check delivers the same 1,955,380 bytes in 30 parts. AHC 2 behaved the same way, so this is hardening, not a regression fix. It matters to consumers that bound their buffering through `ResponseBodyControl`, such as Play WS's streaming API. ## Change **gzip and deflate**, on #2357's loop: - **Before each part**, the handler checks whether the response is suspended. Parts are cut where `JdkZlibDecoder` cuts them, but each `inflate()` call is capped at what is left of a 64 KiB part, so no part is larger. - **While suspended**, the input the inflater has not used yet stays in the handler, together with every message that arrives after it. The chunk is retained, not copied, since the inflater may still point into it; a direct buffer stays allocated until the inflater has used it up. When the output buffer filled up, the inflater may also hold output without any input left; that is remembered, and handed on after the resume. - **On resume**, the handler intercepts the read request that `resume()` issues. It hands on what was held back first, and lets the read reach the socket only if the response is not suspended again. This works the same with auto-read on and off. While paused, `channelReadComplete` does not request a read. - **Without suspension**, each part goes straight through, as before. **br, zstd and snappy**: `PullDecompression` decompresses them one part at a time with Netty's `Decompressor`, under the same checks. Small outputs, such as snappy's frames, are merged into a part sized for them. Outputs larger than 64 KiB, such as zstd's when `io.netty.compression.defaultMaxForwardBytes` is raised, are split into retained slices, so the bound applies to delivered parts, not to allocations. Only this class refers to Netty's `Decompressor`, and it is loaded only once one of these codings shows up. Without the API, which Netty added in 4.2.17, these codings go to `HttpContentDecompressor`'s own decoders, as before. So does zstd when `io.netty.compression.defaultMaxForwardBytes` is 0 or less, where Netty's pull decompressor hands out no output. **For all five content codings**: - **End of the body:** only parts with content wait for a resume. Once the body has been decompressed in full, its end, with any trailers, is handed on even to a suspended response, as for an unencoded body. A consumer whose demand ended with the last part still learns that the body is complete. - **Connection close:** if the connection closes while input is held back, the rest is decompressed and delivered before `channelInactive`, even to a suspended response, because Netty tears the pipeline down with the channel. Suspension no longer bounds that output; only `maxDecompressedResponseSize` does. - **Bodies nobody reads:** once the exchange has ended (cancel, `ABORT`, timeout), or while the channel is drained (after a redirect, an authentication challenge or a replay), the rest of the body is dropped instead of decompressed. Its end still reaches a drain callback. - **The last chunk's decoder result:** `HttpObjectDecoder` reports a chunk it cannot parse as a `LastHttpContent` with a failed result. The end of the body now keeps that result, so the request fails instead of completing with a truncated body. A transfer coding such as `Transfer-Encoding: gzip` still goes through Netty's decoder, which drops it, as on `main`. A suspension made from another thread takes effect when its queued task runs. Until then, the event loop can keep reading and decompressing, as before. ### Why HTTP/2 decompression is unchanged After `END_STREAM`, Netty's HTTP/2 stream channel hands every queued frame over on the next read, regardless of `autoRead`, and then closes. So a handler in the stream pipeline cannot hold compressed input back, and would have to inflate up to a whole stream window at once (16 MiB by default). That is exactly the decompression-bomb case, so a partial fix would be misleading. It needs either a Netty change (honor demand after `END_STREAM` and close only when drained), proposed in netty/netty#17774, or AHC delivering the body independently of the stream channel. ## Behavior changes - **Suspended HTTP/1.1 responses** with one of these content codings receive no further part with content until they resume. A handler that suspends after each part receives one part of at most 64 KiB per resume. The empty last part, trailers and completion still arrive while suspended once the body has been decompressed in full. - **Connection close while suspended:** what the decompressor still holds is delivered at once, bounded only by `maxDecompressedResponseSize`, not by demand. This applies to any close that finds input held back, not only to bodies delimited by the close. - **Drains:** a body with one of these content codings is no longer decompressed while it is drained. Before, a body beyond `maxDecompressedResponseSize` failed the drain, closed its connection and could fail the request that followed on the same future, for example when a `ResponseFilter` replays it. Redirects and 401 or 407 challenges with a compressed body usually close the connection instead of draining it, because the decompressed response looks chunked to them, as on `main`. - **Parts** of these codings are at most 64 KiB. With AHC's default chunk size of 8 KiB, gzip and deflate parts were 64 KiB already; a larger chunk could inflate into a larger part before. For br, zstd and snappy, small outputs are now merged and large ones split, so their part counts differ from Netty's decoders. - **Framing errors** on the final chunk of a body in one of these content codings, such as a bad chunk size, now fail the request. Before, it completed with a truncated body. A transfer coding is unchanged. - **br, zstd and snappy wait for demand with Netty 4.2.17 or later.** With an older Netty, they are decompressed by Netty's own decoders as soon as they are read, as before. gzip and deflate do not use the API. - **Unchanged:** a transfer coding (`Transfer-Encoding: gzip`) is still decoded by Netty's `HttpContentDecompressor`, as on `main`: as soon as it is read, also while suspended or drained, and in Netty's parts. `ResponseBodyControl.suspend()` says so. After a failure, such as the size limit, what is left of the body is dropped, its end included, as on `main`. ## Compatibility - **API:** `Http1ContentDecompressor` keeps its superclass, `HttpContentDecompressor`, and its constructor. It now also implements `ChannelOutboundHandler`, and gains the public methods of that interface, which pass every outbound event through and only look at read requests. Revapi reports no problem. - **Netty:** AHC uses Netty 4.2.19. Only br, zstd and snappy use Netty's `Decompressor` API, added in 4.2.17, and fall back to Netty's own decoders without it. Netty still marks it as unstable (`@UnstableApi`) while it migrates its codecs to it ([netty/netty#16743](netty/netty#16743)), so a future Netty release may require changes to `PullDecompression`. The README says what the version buys. - **Performance:** not measured again for this revision. Without suspension, gzip and deflate run #2357's loop plus the checks before each part; br, zstd and snappy use Netty's pull decompressors instead of its stream decoders. ## Follow-ups - At the end of the body, check that the compressed stream is complete, so a body cut off in the middle of a gzip member, or missing its checksum, fails instead of completing. For gzip and deflate that means the inflater's state and the gzip trailer, for br, zstd and snappy the pull decoder's `endOfInput()`. That changes behavior `main` has, so it gets its own pull request. - Output that is still held when the connection closes, and its HTTP/2 counterpart: the output of the final DATA frame once the stream channel closes (netty/netty#17774 is a prerequisite for HTTP/2). They are related, but may need different fixes. ## Review fixes Four commits on top, one per review finding, each with a test that fails without it: inflate buffers are capped at the part size, so a large codec chunk no longer gives every 64 KiB part a buffer twice the chunk's size; br, zstd and snappy fall back to Netty's own decoders when the `Decompressor` API is missing instead of failing; zstd is left to Netty at a forwarding threshold of 0, where its pull decompressor hands out nothing and the loop never ended; and the README and Javadoc say when these codings wait for demand. ## AI disclosure Claude Code on behalf of Matthias Kurz. The commits include `Co-Authored-By` per `AGENTS.md`. ## Test plan New and changed tests: - **`Http1DecompressionSuspensionTest` (10 tests, live server):** the bound with auto-read on and off, connection reuse, a chunked body with trailers, a body ended by connection close, cancel, `ABORT`, `HEAD` and empty gzip responses, a replay while input is held back with auto-read on and off, and a `ResponseFilter` replay of a body that inflates far beyond the limit, whose drained connection must go back to the pool. - **`Http1ContentDecompressorSuspensionTest` (18 tests, `EmbeddedChannel`):** - one part per read, suspension before the body, and the end of a fully inflated body without another resume, also for a body without bytes; - close while input is held, removal releasing it, and the size limit on the resume path; - suspension across a gzip member boundary, and every coding with fragmented input and a resume per part, with auto-read on and off; - a direct and a pooled direct chunk paused mid-way: held while paused (`refCnt` 1 after the decoder has returned), body correct after resuming, released at the end; - a held direct chunk released on removal, on close and on failure; - output the inflater still holds without input: raw deflate bodies of 64 KiB plus a few bytes, of which 13 sizes pause in exactly that state, checked through package-private test accessors; - a drained or discarded channel: the body is not inflated, its end is handed on. - **`Http1ContentDecompressorTest` (#2357's, 34 tests):** its comparisons with Netty now expect more parts where Netty hands on a part larger than 64 KiB, which happens in 3 of its scenarios; bodies, errors, the end of the response and releases are compared as before, and every part must be at most 64 KiB. New: a failed decoder result on the last chunk; br, zstd and snappy decoded like Netty's decoders, with every split of #2357's helper, from heap and direct buffers; the size limit for those codings; merged parts sized for their content; read requests with auto-read off compared with Netty's for those codings too; and a class loader that hides Netty's `Decompressor` API, under which gzip and deflate decode and a zstd response fails with a `LinkageError`. The test that mixes this handler's messages with Netty's in one read now uses a transfer coding, since snappy is no longer left to Netty. - **`Http1ContentDecompressorForwardThresholdTest` (1 test):** in a fresh JVM with `-Dio.netty.compression.defaultMaxForwardBytes=0`, which hands on the output of every inflate step, a 200,000-byte gzip body is decoded at once and with a suspension after each part. The parent waits at most 60 seconds and kills the child. - **`Http1ContentDecompressorLargeOutputTest` (1 test):** in a fresh JVM with `-Dio.netty.compression.defaultMaxForwardBytes=262144`, checks that zstd output really exceeds 64 KiB, that parts stay within 64 KiB, one per resume, and that a tracking allocator sees every buffer released, also when the handler is removed while it holds the rest of a split output. Broken variants, each run against these test classes: - [x] Without the suspension check: 16 failures and 2 errors, including both bound tests, which report the 1,955,380 bytes in 30 parts from above. - [x] Read requests passed straight through: 15 failures and 2 errors, including the chunked-body test and both replay tests. - [x] Held input not handed on when the connection closes: 2 failures, the close-delimited body test and the `channelInactive` ordering test. - [x] Parts not capped at 64 KiB: 3 failures, the comparisons with Netty where a large chunk inflates at once. - [x] Each inflate call capped by the forwarding threshold instead of the part size: the zero-threshold test hits its 60-second limit, as the inflater is asked for 0 bytes forever. - [x] Held input kept as a slice without retaining it: 18 failures and 3 errors, including both direct-buffer tests. - [x] Output still held by the inflater not restored on resume: 1 failure, the held-output test, which loses the last byte of a 65,537-byte body. - [x] A drained body inflated anyway: 3 failures, the `ResponseFilter` replay test and both unit variants. - [x] A failed decoder result dropped: 1 failure, the last-chunk test. Runs: - [x] Each commit compiles with its tests. - [x] `./mvnw -B -ntp -Dgpg.skip=true clean verify` on JDK 11: 1,856 tests, 0 failures, 0 errors, 11 skipped; Revapi passed. No test-skipping flags were used. - [x] The test classes above, `ResponseBodyControlTest` and `Http2ResponseBodyControlTest`, compiled on JDK 11 and run on JDK 17, 21 and 25 (Maven Surefire's `-Djvm`): 83 tests, 0 failures on each. The fresh-JVM test's child runs on the same JDK. - [x] All open AHC changes merged together (this branch, `ResponseBodyControl.execute`, raw `Cookie` headers on retries, suspend/resume order): they merge without conflicts, in every pair, and `./mvnw -B -ntp -Dgpg.skip=true clean install` on JDK 11 passes with 1,903 tests, 0 failures, 0 errors, 11 skipped; Revapi passed. - [x] Play WS against that merged build, Scala 2.13 and 3.3, JDK 17: all tests pass. Its gzip streaming test demands one part early from another thread and finds 0 bytes delivered beyond demand, against 1,875,916 bytes with AHC 3.0.14. The installed AHC jar is byte-identical to the one built, and Play WS's shaded jar contains `PullDecompression`. --------- Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Aayush Atharva <[email protected]>
5 tasks done
hyperxpro
pushed a commit
that referenced
this pull request
## Summary - Upgrades Netty from 4.2.19.Final to 4.2.20.Final. Its [security fixes](https://github.com/netty/netty/releases/tag/netty-4.2.20.Final) include several in modules AHC uses: three out-of-bounds reads in `netty-buffer`, unbounded memory usage in `netty-codec-http2`, insufficient control character neutralization in `netty-codec-http`, insufficient entropy in `netty-resolver-dns`, and an mTLS bypass via session resumption in `netty-handler`. - On 4.2.20, two of AHC's tests fail, both because of Netty changes. This PR adapts AHC to them. ## Change - **Upgrade Netty to 4.2.20.Final, and check the second gzip magic byte:** `JdkZlibDecoder` now rejects a gzip header with a wrong second magic byte (netty/netty#17972). The gzip inflate loop from #2357 follows `JdkZlibDecoder`, and `Http1ContentDecompressorTest` compares the two, so it now checks that byte too. Both bytes are read unsigned, since `0x8b` is negative as a signed byte. - **Keep zstd working at a non-positive threshold:** since netty/netty#17896, the `ZstdDecoder` that `HttpContentDecompressor` creates sizes its output buffers by `io.netty.compression.defaultMaxForwardBytes`. At 0 it hands on an empty body without an error; below 0 it fails with `IllegalArgumentException: initialCapacity : -1`. AHC leaves zstd to that decoder while the property is not positive (#2362), so it now replaces it with a `ZstdDecoder` whose buffers hold `MAX_PART_SIZE`. The size limit still applies, and the body is still decompressed eagerly there, as before. At the default value of the property nothing changes. netty/netty#18289 fixes the decoder in Netty; this workaround is harmless with that fix and can go once AHC requires a Netty version that has it. ## Notes - Netty 4.2.0 to 4.2.4 have no `ZstdDecoder(int)` constructor. Overriding AHC's Netty with one of those and also setting the property to 0 or below would fail zstd responses with a `NoSuchMethodError`. ## AI disclosure Claude Code on behalf of Matthias Kurz. Both commits include `Co-Authored-By` per `AGENTS.md`. ## Test plan - [x] `main` at `5542c9fc4` with `-Dnetty.version=4.2.20.Final`: 1,857 tests, 2 failures: - `Http1ContentDecompressorTest.decodesLikeNettyForEveryBodyAndSplit`, case "gzip second magic byte ignored": Netty now fails that body, AHC did not. - `Http1ContentDecompressorForwardThresholdTest`: "the zstd body differs". - [x] `Http1ContentDecompressorForwardThresholdTest` now runs at thresholds 0 and -1, each in a fresh JVM, and also checks the size limit for zstd and that every exchange releases its input and buffers. On 4.2.20 without the zstd commit it fails at both ("the zstd body differs", "the zstd body did not end"). With it, it passes on 4.2.19 and 4.2.20. - [x] `./mvnw -B -ntp -Dgpg.skip=true clean verify` on JDK 11, on `main` `3e95ec8c2`: 1,905 tests, 0 failures, 0 errors, 11 skipped; Revapi passed. No test-skipping flags were used. - [x] `Http1ContentDecompressorForwardThresholdTest` and `Http1ContentDecompressorTest` compiled on JDK 11 and run on JDK 17, 21 and 25 (Maven Surefire's `-Djvm`): 36 tests each, 0 failures. - [x] This branch merged with #2369: `clean verify` on JDK 11, 1,914 tests, 0 failures, 0 errors, 11 skipped; Revapi passed (run before #2359, #2360 and #2361 were merged, with those three merged in as well). --------- 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
ReviewersUh oh!
There was an error while loading. Please reload this page. AssigneesNo one assignedLabels
None yet
ProjectsMilestoneNo milestoneDevelopmentSuccessfully merging this pull request may close these issues. Avoid an EmbeddedChannel and Inflater per gzip/deflate HTTP/1.1 responseUh oh!
There was an error while loading. Please reload this page. 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. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |