From 35f09a3717f627dec4e2e8835643bdca1c8a98fe Mon Sep 17 00:00:00 2001 From: Eugene K Date: Mon, 28 Aug 2023 14:06:01 -0400 Subject: [PATCH] enable TCP keep-alive on inbound connections this will help with cleaning up stale terminators when SDK endpoints lose connections (in some cases) --- tls/listener.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tls/listener.go b/tls/listener.go index 45c181a..a9a04ab 100644 --- a/tls/listener.go +++ b/tls/listener.go @@ -31,6 +31,11 @@ import ( "time" ) +const ( + // same as golang Dial default + keepAlive = 15 * time.Second +) + var noProtocol = "" var handlerKey = struct{}{} @@ -193,6 +198,13 @@ type sharedListener struct { func (self *sharedListener) processConn(conn *tls.Conn) { log := self.log + + if tcpConn, ok := conn.NetConn().(*net.TCPConn); ok { + _ = tcpConn.SetNoDelay(true) + _ = tcpConn.SetKeepAlive(true) + _ = tcpConn.SetKeepAlivePeriod(keepAlive) + } + // sharedListener.getConfig will select the right handler during handshake based on ClientHelloInfo // no need to do another look up here var handler *protocolHandler