2

i have tried lowering the connection timeout from 60000 to just 100 millseconds to see whether it is breaking or not. But it is working fine even if the response time is more than 2000 millseconds .

Mine is springboot project,please let me know what is the way to test this connection timeout or let me know if i'm doing anything wrong???

@Component("tomcat")
public class TomcatServer {
    private static final Logger LOGGER = LogManager.getLogger(TomcatServer.class);

    @Value("${server.connection.timeout:60000}")
    private int connectionTimeout;

    @Value("${server.connection.keepalive.timeout:60000}")
    private int keepAliveTimeout;

    @Value("${server.connection.keepalive.count:100}")
    private int maxKeepAliveRequests;

    @Bean
    public TomcatEmbeddedServletContainerFactory tomcatFactory(@Autowired final ContextResource primaryDS) {
        final TomcatEmbeddedServletContainerFactory tcFactory = new TomcatEmbeddedServletContainerFactory() {

            @Override
            protected TomcatEmbeddedServletContainer getTomcatEmbeddedServletContainer(
                    final Tomcat tomcat) {
                    tomcat.enableNaming();
                return super.getTomcatEmbeddedServletContainer(tomcat);
            }

            @Override
            protected void postProcessContext(final Context context) {
                context.getNamingResources().addResource(primaryDS);
            }
        };

        tcFactory.addConnectorCustomizers(connector -> {
            final Http11NioProtocol proto = (Http11NioProtocol) connector.getProtocolHandler();

            LOGGER.info("connectionTimeout=" + connectionTimeout);
            LOGGER.info("keepAliveTimeout=" + keepAliveTimeout);
            LOGGER.info("maxKeepAliveRequests=" + maxKeepAliveRequests);
            proto.setConnectionTimeout(connectionTimeout);
            proto.setKeepAliveTimeout(keepAliveTimeout);
            proto.setMaxKeepAliveRequests(maxKeepAliveRequests);
        });

        return tcFactory;
    }
}```
  • There is a property you could set: server.tomcat.connection-timeout but this will not help because the timeout is defined as: "Amount of time the connector will wait, after accepting a connection, for the request URI line to be presented." – Simon Martinelli May 13 '20 at 08:17
  • Does this answer your question? [Tomcat request timeout](https://stackoverflow.com/questions/7145131/tomcat-request-timeout) – Simon Martinelli May 13 '20 at 08:19
  • No, My goal is to set timeout in such a way to break the connection for the incoming http request if the application takes more than 2 seconds processing time.Thanks for reply, – Sivakumar Neelam Veera May 13 '20 at 09:26

0 Answers0