Jerald Baker
Jerald Baker

Reputation: 1369

Tomcat server causing broken pipe for big payloads

I made a simple spring-boot application that returns a static json response for all requests.

When the app gets a request with a large payload (~5mb json, 1 TP ), the client receives the following error:

java.net.SocketException: Broken pipe (Write failed)
    at java.net.SocketOutputStream.socketWrite0(Native Method)
    at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:111)
    at java.net.SocketOutputStream.write(SocketOutputStream.java:155)

I have tried increasing every limit i could - here are my tomcat settings:

spring.http.multipart.max-file-size=524288000
spring.http.multipart.max-request-size=524288000
spring.http.multipart.enabled=true
server.max-http-post-size=10000000
server.connection-timeout=30000
server.tomcat.max-connections=15000
server.tomcat.max-http-post-size=524288000
server.tomcat.accept-count=10000
server.tomcat.max-threads=200
server.tomcat.min-spare-threads=200

What can I do to make this simple spring boot with just one controller, to handle such payloads successfully?

This springboot application and the client sending the large payload run on an 8-core machine with 16gb ram. So resources shouldn't be a problem.

Upvotes: 3

Views: 3181

Answers (1)

Jerald Baker
Jerald Baker

Reputation: 1369

This was because the controller was returning a response without consuming the request body. So the server closes the connection as soon as it receives the request, without consuming the full request body. The client still hadn't finished sending the request and the server closed the connection before that.

Solution: 1. Read the full request body in your code 2. Set tomcat's maxSwallowSize to a higher value (default : 2mb) server.tomcat.max-swallow-size=10MB

Upvotes: 1

Related Questions