Repository navigation
Conversation
Since OpenFeign#2420, Http2Client delivers response bodies via BodyHandlers.ofInputStream(): send() returns as soon as the headers arrive and the body is read lazily. A malformed or truncated body - eg WireMock's Fault.MALFORMED_RESPONSE_CHUNK - then fails during decoding, after client.execute() returned successfully: feign classifies such failures as errorReading (a plain FeignException) instead of the retryable errorExecuting, and with a Response return type the raw IOException escapes the invocation entirely, so retries never fire. Read the head (up to 8KB) of the raw, pre-decompression response body during execute(), mirroring the bounded eager read feign core applies when it buffers response bodies. Transport failures on small responses now surface from execute() as IOExceptions, restoring the retryable classification responses had before the switch to ofInputStream(). Decompression failures keep surfacing in the decoder, and bodies larger than the buffer keep streaming: the buffered head is re-attached in front of the remaining stream, preserving the memory behavior that motivated OpenFeign#2420. The async (AsyncFeign) path is unchanged and keeps streaming lazily. Fixes OpenFeign#2689 Signed-off-by: Inf1mum <vadimlazuk5@gmail.com>
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.
Fixes #2689
Problem
Since #2420,
Http2Clientdelivers response bodies viaBodyHandlers.ofInputStream():send()returns as soon as the response headers arrive and the body is read lazily. A malformed or truncated body — for example WireMock'sFault.MALFORMED_RESPONSE_CHUNK— then fails only when the (now lazy) body stream is read, afterclient.execute()has already returned successfully. Feign classifies such failures aserrorReading(a plainFeignException) instead of the retryableerrorExecuting, and with aResponsereturn type the rawIOExceptionescapes the feign invocation entirely, so retries never fire.Fix
Read the head (up to 8KB — the same bound core uses when it buffers response bodies) of the raw, pre-decompression response body during
execute(). This follows the narrower option proposed in the issue discussion, and the directionveloasked for there: a focused regression test around the WireMock malformed chunk case with the public API unchanged.execute()asIOExceptions, restoring the retryable classification responses had before the switch toofInputStream()(pre-13.3).GZIPInputStream/InflaterInputStreamwrapping intoFeignResponse.AsyncFeign) path is unchanged and keeps streaming lazily.Testing
malformedResponseChunkSurfacesAsRetryableExceptioninHttp2ClientTestemulates WireMock'sFault.MALFORMED_RESPONSE_CHUNK— OkHttp MockWebServer 5.x no longer ships a policy for malformed chunks, so it uses a raw socket like the existinggetWithRequestBody(): valid headers with chunked transfer encoding followed by garbage where a chunk size line belongs. It asserts that both aResponsereturn type (the reporter's scenario) and a decoded return type surfaceRetryableException, and that the retryer actually retried every invocation.The test was confirmed to fail on
master(rawIOExceptionescape for theResponsereturn type, non-retryableFeignExceptionfromerrorReadingfor the decoded type) and to pass with this change.Verification
mvn -pl java11 -Pdev test -Dtoolchain.skip=true -Dlicense.skip=true— main sources compile (Compiling 1 source file with javac [debug target 11]). The forkedtestCompileis pinned to source/target 25, which the local JDK 21 cannot run (error: invalid target release: 25) — the full suite is deferred to CI.Http2ClientTestandHttp2ClientAsyncTest) were compiled with javac and run via the JUnit Platform launcher on JDK 21 — all pass.RetryableExceptionwith the chunk-parse error as cause; 400 + empty deflate body still producesFeignException$BadRequestwith a response body (unchanged from master); a 100KB body still streams with correct length and content.