Skip to content
Permalink
Browse files

Turn on SO_KEEPALIVE by default. Graceful shutdown.

  • Loading branch information...
apangin committed Oct 8, 2019
1 parent ce1fc84 commit ae71e44940856ab87806dce50daa9a19b9d66943
@@ -30,6 +30,7 @@
public int sendBuf;
public int tos;
public int backlog = 128;
public boolean keepAlive = true;
public boolean noDelay = true;
public boolean tcpFastOpen = true;
public boolean deferAccept;
@@ -57,6 +57,7 @@
if (config.tos != 0) serverSocket.setTos(config.tos);
if (config.deferAccept) serverSocket.setDeferAccept(true);

serverSocket.setKeepAlive(config.keepAlive);
serverSocket.setNoDelay(config.noDelay);
serverSocket.setTcpFastOpen(config.tcpFastOpen);
serverSocket.setReuseAddr(true, config.reusePort);
@@ -74,6 +75,7 @@ void reconfigure(AcceptorConfig config) throws IOException {
serverSocket.setTos(config.tos);
}
serverSocket.setDeferAccept(config.deferAccept);
serverSocket.setKeepAlive(config.keepAlive);
serverSocket.setNoDelay(config.noDelay);
serverSocket.setTcpFastOpen(config.tcpFastOpen);
serverSocket.setReuseAddr(true, config.reusePort);
@@ -144,7 +144,7 @@ public synchronized void stop() {
selector.shutdown();
}

workers.gracefulShutdown(30000L);
workers.gracefulShutdown();
}

public void registerShutdownHook() {
@@ -42,14 +42,20 @@ void setQueueTime(long queueTime) {
((WaitingSynchronousQueue) getQueue()).setQueueTime(queueTime);
}

void gracefulShutdown(long timeout) {
void gracefulShutdown() {
shutdown();
try {
awaitTermination(timeout, TimeUnit.MILLISECONDS);
awaitTermination(20, TimeUnit.SECONDS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}

shutdownNow();
try {
awaitTermination(10, TimeUnit.SECONDS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}

@Override

0 comments on commit ae71e44

Please sign in to comment.
You can’t perform that action at this time.