and maxKeepAliveRequests See #23539
Comment From: wilkinsona
@parviz-93 Thank you very much for making your first contribution to Spring Boot. Your changes have now been merged along with a small polishing commit.
Comment From: parviz-93
@wilkinsona Thanks a lot for this experience. Thanks a lot for this experience. If there are still such tasks, I am ready to contribute to my favorite framework
Comment From: aplatt
It looks like the keep-alive timeout only worked for HTTP/1.1. The timeout for HTTP/2 was still 20s. This is how I got around it based on a @shunminli example:
@Configuration
public class TomcatCustomizer implements WebServerFactoryCustomizer<TomcatServletWebServerFactory>
{
@Value("${server.http.keep-alive-timeout:}")
private int httpKeepAliveTimeout;
@Value("${server.http2.keep-alive-timeout:}")
private long http2KeepAliveTimeout;
private static final Logger log = LoggerFactory.getLogger(TomcatCustomizer.class);
@Override
public void customize(TomcatServletWebServerFactory factory) {
factory.addConnectorCustomizers(connector -> {
AbstractHttp11Protocol protocol = (AbstractHttp11Protocol) connector.getProtocolHandler();
int originMaxKeepAliveRequests = protocol.getMaxKeepAliveRequests();
protocol.setMaxKeepAliveRequests(-1);
int originKeepAliveTimeout = protocol.getKeepAliveTimeout();
protocol.setKeepAliveTimeout(httpKeepAliveTimeout);
log.info(
"####################################################################################");
log.info("#");
log.info("# TomcatCustomizer HTTP");
log.info("#");
log.info("# origin maxKeepAliveRequests {}", originMaxKeepAliveRequests);
log.info("# custom maxKeepAliveRequests {}", protocol.getMaxKeepAliveRequests());
log.info("# origin keepalive timeout: {} ms", originKeepAliveTimeout);
log.info("# keepalive timeout: {} ms", protocol.getKeepAliveTimeout());
log.info("# connection timeout: {} ms", protocol.getConnectionTimeout());
log.info("# max connections: {}", protocol.getMaxConnections());
log.info("#");
log.info(
"####################################################################################");
});
factory.addConnectorCustomizers(connector -> {
Http2Protocol protocol = (Http2Protocol) connector.findUpgradeProtocols()[0];
long originKeepAliveTimeout = protocol.getKeepAliveTimeout();
protocol.setKeepAliveTimeout(http2KeepAliveTimeout);
log.info(
"####################################################################################");
log.info("#");
log.info("# TomcatCustomizer HTTP/2");
log.info("#");
log.info("# origin keepalive timeout: {} ms", originKeepAliveTimeout);
log.info("# keepalive timeout: {} ms", protocol.getKeepAliveTimeout());
log.info("#");
log.info(
"####################################################################################");
});
}
}
Comment From: bclozel
@aplatt it sounds like these properties should also cover the HTTP/2 protocol. Could you create a new issue for that?
Comment From: aplatt
I created issue #30267