Skip to content

Support consistent resource clean up on ClientHttpRequestFactory #35971

@lenin-jaganathan

Description

@lenin-jaganathan

See #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. #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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions