spring-cloud / spring-cloud/spring-cloud-gateway
Connection pool leak in spring-cloud-gateway-server-mvc when retrying with Apache HTTP client
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 4.9k
- Forks
- 3.5k
- Avg merge
- 20h 57m
- Merged PRs (30d)
- 8
Description
Describe the bug
I suspect that leased connections are not released back into the connection pool when an error is encountered, and the Apache HTTP client is used in combination with the retry filter. I think it is because the response body is not read before throwing a RetryException.
It seems that if something like the following is added to RetryFilterFunctions, right before this line of code, the connections get released back again:
InputStream responseInputStream = MvcUtils.getAttribute(request, MvcUtils.CLIENT_RESPONSE_INPUT_STREAM_ATTR);
StreamUtils.copy(responseInputStream, OutputStream.nullOutputStream());
Sample
Here is a repo that reproduces the issue: https://github.com/johan1a/spring-cloud-gateway-mvc-connection-test/tree/master
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 with spring-cloud-gateway-server-mvc/src/main/java/org/springframework/cloud/gateway/server/mvc/filter/RetryFilterFunctions.java around the linked line, then inspect the MvcUtils client-response input-stream attribute and the linked reproduction repository. Verify the retry path releases leased Apache HTTP client connections when an error occurs, and confirm the reproduction no longer shows the connection-pool leak.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring, spring-boot
- Domain
- api, backend, networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100