Adam
Adam

Reputation: 5445

Setting tomcat connectionUploadTimeout in Spring Boot

I want to try to set the Tomcat connectionUploadTimeout property within Spring Boot 2. I'm getting some random non-reproducible java.net.SocketTimeoutException: null in my server logs.

It's coming from the request input stream, so if I can set this property to a really short duration, then I should be able to replicate it locally.

I've tried

server.disableUploadTimeout=false
server.connectionUploadTimeout=5000

and

server.tomcat.disableUploadTimeout=false
server.tomcat.connectionUploadTimeout=5000

and

server.tomcat.disable-upload-timeout=false
server.tomcat.connection-upload-timeout=5000

but still my 15 seconds requests locally are completing without any time-outs.

The Spring docs are not very helpful here.

Upvotes: 2

Views: 5056

Answers (1)

Andy Wilkinson
Andy Wilkinson

Reputation: 116171

There's no need to guess which properties are supported as they're all listed in an appendix in the reference documentation. As you can hopefully see, there are no properties for configuring the connection upload timeout or for enabling the upload timeout on a Connector. This means that those properties must be configured programatically.

You can configure the Connector programmatically using a Tomcat-specific WebServerFactoryCustomizer:

@Bean
public WebServerFactoryCustomizer<TomcatServletWebServerFactory> tomcatCustomizer() {
    return (tomcat) -> tomcat.addConnectorCustomizers((connector) -> {
        if (connector.getProtocolHandler() instanceof AbstractHttp11Protocol) {
            AbstractHttp11Protocol<?> protocolHandler = (AbstractHttp11Protocol<?>) connector
                    .getProtocolHandler();
            protocolHandler.setDisableUploadTimeout(false);
            protocolHandler.setConnectionUploadTimeout(5000);
        }
    });
}

Upvotes: 5

Related Questions