Skip to content

Restore Apache HTTP4 retries for bodyless idempotent requests - #3634

Merged
velo merged 2 commits into
OpenFeign:masterfrom
hutiefang76:frank/thirty-feign-emptyget-20261019
Nov 9, 2026
Merged

velo merged 2 commits into
OpenFeign:masterfrom
hutiefang76:frank/thirty-feign-emptyget-20261019

Conversation

@hutiefang76

Copy link
Copy Markdown
Contributor

A bodyless GET sent through ApacheHttpClient does not use Apache HttpClient 4’s internal connection retry: Feign adds an empty entity, so Apache classifies the request as entity-enclosing. ByteArrayEntity itself is repeatable; the missing retry comes from the idempotency check.

This change omits the empty entity for bodyless GET, HEAD, OPTIONS, TRACE and DELETE requests. Other methods retain the existing empty entity, and requests with bodies keep their existing conversion. This preserves POST/PUT query placement and avoids introducing internal retries for POST, PATCH or QUERY. The HC5 adapter is unchanged.

Validation used Java 8 for main sources and Temurin 25.0.4.1 for tests, with the development profile, license checks and formatter enabled:

  • Original implementation: 13 focused tests, with five expected NoHttpResponseException errors for the five eligible methods; the eight controls passed.
  • Fixed implementation: ./mvnw -Pdev -pl httpclient -am clean verify passed: 867 tests, no failures or errors, four existing conditional skips in core. All 48 HTTP4 adapter tests passed without skips.
  • Root ./mvnw -Pdev validate passed.

The connection-loss tests use the real Apache client against MockWebServer, disconnect after the request has been received, and bypass Feign’s outer retryer. They check that eligible methods retry, while bodyless POST/PUT/PATCH/QUERY and a POST with a body do not. GET-with-body preservation is checked at request conversion because MockWebServer does not accept that exchange.

Fixes #2115

AI-assisted investigation and implementation for @hutiefang76.

Omit empty entities for GET, HEAD, OPTIONS, TRACE and DELETE so Apache's
internal idempotency check can retry a lost connection. Keep the existing
entity for other methods and for requests with bodies.

Add real connection-loss regressions and request-shape controls.

Fixes OpenFeign#2115

@velo velo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Checked against RequestBuilder in httpclient 4.5: the empty entity was added in 1b09f0f (2016) only to stop RequestBuilder turning query params into a form body, which it does for POST/PUT alone, so dropping it for GET/HEAD/OPTIONS/TRACE/DELETE is safe and POST/PUT/PATCH/QUERY/CONNECT keep the entity and stay non-retried. The lost-connection tests fail without the change and the POST/PATCH controls guard against double-sending non-idempotent requests. Nits: "Restore" in the title is a stretch since these were never retried after that commit, and the test javadocs are longer than the rest of the class.

@velo
velo enabled auto-merge (squash) November 9, 2026 20:35
@velo

velo commented Nov 9, 2026

Copy link
Copy Markdown
Member

Approved, but this now conflicts with master in CHANGELOG.md (a 13.18 section was added by another merge). Could you merge or rebase master and append your entry under the existing ### Version 13.18 heading? Auto-merge is enabled, so it will land once checks pass.

Signed-off-by: Marvin Froeder <velo.br@gmail.com>

# Conflicts:
#	CHANGELOG.md
@velo

velo commented Nov 9, 2026

Copy link
Copy Markdown
Member

Merged master; CHANGELOG.md was removed from the repo so the entry was dropped.

@velo
velo merged commit 2787227 into OpenFeign:master Nov 9, 2026
3 checks passed
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.

Don't use zero-length ByteArrayEntities for requests without a body in ApacheHttpClient

2 participants