spring-projects / spring-boot

Spring Boot helps you to create Spring-powered, production-grade applications and services with absolute minimum fuss.
https://spring.io/projects/spring-boot
Apache License 2.0
75.08k stars 40.67k forks source link

EOFException in Service A when handling multipart uploads over 300KB via Cloud Gateway in Spring Boot 3.3.4+ #42940

Closed Zanfo96 closed 2 days ago

Zanfo96 commented 2 days ago

Hello,

We recently encountered an issue in our Java-Spring Boot project related to handling multipart/form-data uploads in a microservices architecture. Here’s a brief overview of our setup:

Architecture: Client → Cloud Gateway→ Service A

Cloud Gateway: A standard Spring Boot application serving as a gateway for HTTP requests, performing filtering, header modifications, and routing to specific microservices. Service A: A microservice receiving file uploads forwarded by Cloud Gateway. Problem: After upgrading to Spring Boot 3.3.4 and continuing into 3.3.5, Service A started throwing EOFException errors for larger multipart uploads (file sizes above ~250–300KB). For "large" files, the transfer encoding header is "Transfer-Encoding: chunked".

Evidence: When making the same upload request directly to Service A’s endpoint (bypassing Cloud Gateway), the upload completes successfully with no errors. This indicates that the issue is likely related to how Cloud Gateway handles or forwards these larger multipart requests.

Exception Stack Trace: Here is a portion of the stack trace from Service A:

org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request
    at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.handleParseFailure(StandardMultipartHttpServletRequest.java:131)
    ...
    Caused by: org.apache.catalina.connector.ClientAbortException: java.io.EOFException
        at org.apache.catalina.connector.InputBuffer.realReadBytes(InputBuffer.java:312)
        ...
Caused by: java.io.EOFException
    at org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.fillReadBuffer(NioEndpoint.java:1270)

Environment: Both the Cloud Gateway and Service A are Spring Boot applications. Only the Cloud Gateway uses Spring Cloud. Observation: The issue is specific to files uploaded via chunked transfer encoding and only occurs for file sizes exceeding a threshold (roughly 250–300KB). Could you please advise on how to resolve or troubleshoot this EOFException when handling multipart requests through Cloud Gateway in Spring Boot 3.3.4+?

Thank you!

mhalbritter commented 2 days ago

Did you also upgrade the Boot version of the Cloud Gateway?

Did you test with the unchanged Cloud Gateway and the updated Service A?

wilkinsona commented 2 days ago

This indicates that the issue is likely related to how Cloud Gateway handles or forwards these larger multipart requests

This seems like a reasonable conclusion. Please open a Spring Cloud Gateway issue so that the Cloud team can investigate in the first instance. When you do so, please provide a complete yet minimal sample that reproduces the problem.