spring-projects / spring-projects/spring-framework
Support consistent resource clean-up on ClientHttpRequestFactory
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 60.2k
- Forks
- 38.8k
- Avg merge
- 5d 2h
- Merged PRs (30d)
- 27
Description
See https://github.com/spring-projects/spring-framework/issues/29370 for context
Background:
We declaratively create RestClients during start-up based on the configurations. We keep track of the created clients and need to refresh the client (basically create a fresh one) on refresh (config changes, certificate changes, etc.). When doing so, we were not able to properly clean up the resources associated with the existing client (like connection pools, etc) because ClientHttpRequestFactory does not support it by default. We are worried about the resource leaks due to referencing clients without closing them properly.
The current workaround we use is to rely on implementations of ClientHttpRequestFactory. Some of them do implement AutoClosable/DisposableBean/Lifecycle, and we use this to close the resource, but implementations like JdkClientHttpRequestFactory do not implement any of these.
It would be great if ClientHttpRequestFactory implements AutoCloseable to support resource clean-up. https://github.com/spring-projects/spring-framework/issues/29370 attempted to fix this, but got reverted due to some other issues with RestTemplate. It would be great to revisit this and, in the worst case, make the implementations extend a consistent interface to support clean-ups.
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 ClientHttpRequestFactory and JdkClientHttpRequestFactory, then read issue #29370 for the earlier attempted change and its RestTemplate-related concerns. Determine a consistent resource-cleanup contract for request-factory implementations, including refresh scenarios involving connection pools and other client resources. Done means existing clients can be cleaned up reliably when replaced without reintroducing the earlier RestTemplate issues.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100