spring-cloud / spring-cloud-commons

Common classes used in different Spring Cloud implementations
Apache License 2.0
698 stars 690 forks source link

Load Balancer RequestInterceptor breaks large file uploads #1355

Open ZIRAKrezovic opened 1 month ago

ZIRAKrezovic commented 1 month ago

Describe the bug

This is basically present in anything that implements a ClientRequestInterceptor. See the original bug report for Spring Framework, along with reproducer that uses spring-cloud-starter-loadbalancer and SimpleLoadBalancer.

As it turns out, adding a ClientRequestInterceptor to a RestClient or RestTemplate results in it being wrapped in "Buffering" factory rather than "Streaming" factory, effectively breaking the streaming functionality required for large file upload. This makes usage of load balancer client unsuitable for transferring large files between microservices that communicate via load balancer addresses.

Spring framework developer has responded that they have no plan to fix this or provide a solution, as the ClientRequestInterceptor contract is fixed.

Is there an alternative for spring cloud loadbalancer implementation to implement something other than ClientRequestInterceptor and achieve the same functionality?

https://github.com/spring-projects/spring-framework/issues/32879 https://github.com/ZIRAKrezovic/spring-multipart-reproducer

Sample If possible, please provide a test case or sample application that reproduces the problem. This makes it much easier for us to diagnose the problem and to verify that we have fixed it.

OlgaMaciaszek commented 2 weeks ago

@ZIRAKrezovic - yes, it's there; you can use a WebClient instance created with @LoadBalanced WebClient.Builder to achieve this. You can also use it as the base of client for Spring Interface Clients if you do not want to work directly with the reactive API.

ZIRAKrezovic commented 2 weeks ago

Yes, I personally use web client, but sadly not everybody wants webflux as a dependency in webmvc application.