Repository navigation
Restore Apache HTTP4 retries for bodyless idempotent requests - #3634
Conversation
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
left a comment
There was a problem hiding this comment.
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.
|
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 |
Signed-off-by: Marvin Froeder <velo.br@gmail.com> # Conflicts: # CHANGELOG.md
|
Merged master; CHANGELOG.md was removed from the repo so the entry was dropped. |
A bodyless GET sent through
ApacheHttpClientdoes not use Apache HttpClient 4’s internal connection retry: Feign adds an empty entity, so Apache classifies the request as entity-enclosing.ByteArrayEntityitself 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:
NoHttpResponseExceptionerrors for the five eligible methods; the eight controls passed../mvnw -Pdev -pl httpclient -am clean verifypassed: 867 tests, no failures or errors, four existing conditional skips in core. All 48 HTTP4 adapter tests passed without skips../mvnw -Pdev validatepassed.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.