spring-cloud-gateway icon indicating copy to clipboard operation
spring-cloud-gateway copied to clipboard

Add request temp file buffer (#3479)

Open Milkdove opened this issue 1 year ago • 3 comments

Add the feature of using temp file as intermediaries when forwarding large requests, which can effectively solve the OOM, and added two configs to control it:

spring.cloud.gateway.mvc.file-buffer-enabled 
spring.cloud.gateway.mvc.file-buffer-size-threshold

I'm not sure if this solution is appropriate. It may cause some large requests to be slowed down.But I don’t have any other ideas at the moment. This is the solution our team uses. In addition, should the default value of file-buffer-enabled be true?

Milkdove avatar Jan 07 '25 09:01 Milkdove

Shouldn't the gateway stream the file? Or are you using filters that may be reading the body?

ryanjbaxter avatar Mar 13 '25 18:03 ryanjbaxter

Strictly speaking, the current MVC version of the Gateway doesn't truly support streaming transmission. Its process involves reading the request, caching it, and then sending it out. This approach can lead to Out Of Memory (OOM) issues, as seen in some cases. To achieve streaming forwarding, you'd need to modify the underlying network framework to use asynchronous I/O, like with a WebFlux Gateway. However, this means moving away from the traditional MVC architecture.

Milkdove avatar Mar 18 '25 09:03 Milkdove

This version was built specifically for Spring WebMVC and blocking IO is part of that. When Zuul was supported, there was an option to install it as a servlet outside the spring dispatcher servlet, and that's how large uploads were handled. We don't really have either of those options. This seems like a good middle ground.

spencergibb avatar Mar 22 '25 14:03 spencergibb