Don't use zero-length ByteArrayEntities for requests without a body in ApacheHttpClient
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 9.8k
- Forks
- 1.9k
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 41
Description
I've been checking out the behaviour of Apache's HttpClient with reusing pooled connections lately, and found a little unneccessity in OpenFeign's ApacheHttpClient that makes live more difficult:
If an open HTTP connection in HttpClient's connection pool is closed from the server side (or an intermediate firewall or load balancer or whatever), HttpClient does have an automatic retry mechanism that, on certain exception types and when various preconditions are fulfilled, retry fetching a connection.
One of these preconditions is that the request must not have a stream based body, since these are generally not repeatable.
Unfortunately, OpenFeign's ApacheHttpClient adds a zero-lengh ByteArrayEntity to the request if the request does not have a body, thus rendering HttpClient in a "don't retry" state.
Adding the zero-length ByteArrayEntity is not neccessary, the request just works fine without it, and then is repeatable in certain problem cases.
Note that for POST requests or any other request with a body this won't help, since obviously then you'll have a body and thus a (not empty) ByteArrayEntity. But it will help with some of the requests.
Also note that Apache's HttpClient by now has an option to check stale conditions in the pool if they've been lingering around in idle state for a configured time. This avoids a check in cases with high enough load (then the connection won't be as quickly disconnected from the other side) and still does the check in cases where it is appropriate. You'll have to set up your own PoolingHttpClientConnectionManager object for HttpClient however, to be able to set its option setValidateAfterInactivity(...). This setting helps in cases where we do have a streamed entitty in the request, but it might not help in other cases when the connection is lost before it is validated due to the inactivity timeout.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the ApacheHttpClient request-construction entry point and trace how requests without bodies receive a ByteArrayEntity. Confirm that bodyless requests omit the zero-length entity while requests with bodies retain their entity, then add or update coverage for both cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100