Skip to content

Restore retryable classification for Http2Client response body failures - #3694

Open
Inf1mum wants to merge 1 commit into
OpenFeign:masterfrom
Inf1mum:fix/2689-java11-retry
Open

Inf1mum wants to merge 1 commit into
OpenFeign:masterfrom
Inf1mum:fix/2689-java11-retry

Conversation

@Inf1mum

@Inf1mum Inf1mum commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Fixes #2689

Problem

Since #2420, Http2Client delivers response bodies via BodyHandlers.ofInputStream(): send() returns as soon as the response headers arrive and the body is read lazily. A malformed or truncated body — for example WireMock's Fault.MALFORMED_RESPONSE_CHUNK — then fails only when the (now lazy) body stream is read, after client.execute() has already 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 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 direction velo asked for there: a focused regression test around the WireMock malformed chunk case with the public API unchanged.

  • Transport failures on small responses (malformed chunked transfer encoding, truncation) now surface from execute() as IOExceptions, restoring the retryable classification responses had before the switch to ofInputStream() (pre-13.3).
  • Decompression failures (gzip/deflate) keep surfacing in the decoder where they did before: the eager read is applied to the raw stream, before the GZIPInputStream / InflaterInputStream wrapping in toFeignResponse.
  • 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 http2client should not cache the InputStream #2420.
  • The eager read and the remaining stream are guarded by the configured read timeout.
  • The async (AsyncFeign) path is unchanged and keeps streaming lazily.

Testing

malformedResponseChunkSurfacesAsRetryableException in Http2ClientTest emulates WireMock's Fault.MALFORMED_RESPONSE_CHUNK — OkHttp MockWebServer 5.x no longer ships a policy for malformed chunks, so it uses a raw socket like the existing getWithRequestBody(): valid headers with chunked transfer encoding followed by garbage where a chunk size line belongs. It asserts that both a Response return type (the reporter's scenario) and a decoded return type surface RetryableException, and that the retryer actually retried every invocation.

The test was confirmed to fail on master (raw IOException escape for the Response return type, non-retryable FeignException from errorReading for the decoded type) and to pass with this change.

Verification

  1. mvn -pl java11 -Pdev test -Dtoolchain.skip=true -Dlicense.skip=true — main sources compile (Compiling 1 source file with javac [debug target 11]). The forked testCompile is pinned to source/target 25, which the local JDK 21 cannot run (error: invalid target release: 25) — the full suite is deferred to CI.
  2. As a local substitute, all 6 java11 test classes (109 tests, incl. Http2ClientTest and Http2ClientAsyncTest) were compiled with javac and run via the JUnit Platform launcher on JDK 21 — all pass.
  3. Standalone probes against the change: malformed chunk → RetryableException with the chunk-parse error as cause; 400 + empty deflate body still produces FeignException$BadRequest with a response body (unchanged from master); a 100KB body still streams with correct length and content.

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>
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.

Retry issue after migration to 13.5

1 participant