Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Graceful Shutdown in Jetty #1651

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.ripe.db.whois.api.httpserver;

import com.google.common.util.concurrent.Uninterruptibles;
import io.netty.handler.ssl.util.TrustManagerFactoryWrapper;
import jakarta.servlet.DispatcherType;
import net.ripe.db.whois.api.httpserver.dos.WhoisDoSFilter;
Expand Down Expand Up @@ -46,6 +47,8 @@
import java.util.Collection;
import java.util.EnumSet;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

// TODO: [ES] remove duplicate code from InternalJettyBootstrap in whois-internal
@Component
Expand Down Expand Up @@ -221,7 +224,9 @@ private Server createServer() {
setConnectors(server);
server.setHandler(handlers);

server.setStopAtShutdown(false);
server.setStopAtShutdown(false); // don't stop immediately
server.setStopTimeout(30_000L);

server.setRequestLog(createRequestLog());

if (rewriteEngineEnabled) {
Expand Down Expand Up @@ -258,7 +263,13 @@ private void setConnectors(final Server server) {
private Connector createInsecureConnector(final Server server, final HttpConfiguration httpConfiguration) {
httpConfiguration.setIdleTimeout(idleTimeout * 1000L);
httpConfiguration.setUriCompliance(UriCompliance.LEGACY);
final ServerConnector connector = new ServerConnector(server, new HttpConnectionFactory(httpConfiguration), new HTTP2CServerConnectionFactory(httpConfiguration));
final ServerConnector connector = new ServerConnector(server, new HttpConnectionFactory(httpConfiguration), new HTTP2CServerConnectionFactory(httpConfiguration)) {
@Override
public CompletableFuture<Void> shutdown() {
return CompletableFuture.runAsync(() -> {Uninterruptibles.sleepUninterruptibly(20_000L, TimeUnit.MILLISECONDS);});
}
};
connector.setShutdownIdleTimeout(20_000L);
connector.setPort(this.port);
return connector;
}
Expand Down Expand Up @@ -339,8 +350,14 @@ protected TrustManagerFactory getTrustManagerFactoryInstance() {

final SslConnectionFactory sslConnectionFactory = new SslConnectionFactory(sslContextFactory, alpn.getProtocol());

final ServerConnector sslConnector = new ServerConnector(server, sslConnectionFactory, alpn, h2, new HttpConnectionFactory(httpsConfiguration));
final ServerConnector sslConnector = new ServerConnector(server, sslConnectionFactory, alpn, h2, new HttpConnectionFactory(httpsConfiguration)) {
@Override
public CompletableFuture<Void> shutdown() {
return CompletableFuture.runAsync(() -> {Uninterruptibles.sleepUninterruptibly(20_000L, TimeUnit.MILLISECONDS);});
}
};
sslConnector.setPort(port);
sslConnector.setShutdownIdleTimeout(20_000L);
return sslConnector;
}

Expand Down