From ee907f7149dfae7f757bf9c7b257c1ba82a875ef Mon Sep 17 00:00:00 2001 From: Bjørn Christian Seime Date: Tue, 11 May 2021 12:50:04 +0200 Subject: Handle case where SslConnection is opened but SSL listener not invoked Empty entries in 'sslToConnectionInfo' when SSL/ALPN connection is closed. --- .../yahoo/jdisc/http/server/jetty/JettyConnectionLogger.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/container-core/src/main/java/com/yahoo/jdisc/http/server/jetty/JettyConnectionLogger.java b/container-core/src/main/java/com/yahoo/jdisc/http/server/jetty/JettyConnectionLogger.java index bbeccb61c8a..1923153f970 100644 --- a/container-core/src/main/java/com/yahoo/jdisc/http/server/jetty/JettyConnectionLogger.java +++ b/container-core/src/main/java/com/yahoo/jdisc/http/server/jetty/JettyConnectionLogger.java @@ -6,6 +6,7 @@ import com.yahoo.container.logging.ConnectionLogEntry; import com.yahoo.container.logging.ConnectionLogEntry.SslHandshakeFailure.ExceptionEntry; import com.yahoo.io.HexDump; import com.yahoo.jdisc.http.ServerConfig; +import org.eclipse.jetty.alpn.server.ALPNServerConnection; import org.eclipse.jetty.http2.server.HTTP2ServerConnection; import org.eclipse.jetty.io.Connection; import org.eclipse.jetty.io.EndPoint; @@ -124,6 +125,14 @@ class JettyConnectionLogger extends AbstractLifeCycle implements Connection.List if (info == null) return; // Closed connection already handled if (connection instanceof HttpConnection) { info.setHttpBytes(connection.getBytesIn(), connection.getBytesOut()); + } else if (connection instanceof SslConnection) { + SSLEngine sslEngine = ((SslConnection) connection).getSSLEngine(); + sslToConnectionInfo.remove(IdentityKey.of(sslEngine)); + } else if (connection instanceof ALPNServerConnection) { + SSLEngine sslEngine = ((ALPNServerConnection) connection).getSSLEngine(); + if (sslEngine != null) { + sslToConnectionInfo.remove(IdentityKey.of(sslEngine)); + } } if (!endpoint.isOpen()) { info.setClosedAt(System.currentTimeMillis()); @@ -170,6 +179,7 @@ class JettyConnectionLogger extends AbstractLifeCycle implements Connection.List SSLEngine sslEngine = event.getSSLEngine(); handleListenerInvocation("SslHandshakeListener", "handshakeSucceeded", "sslEngine=%h", List.of(sslEngine), () -> { ConnectionInfo info = sslToConnectionInfo.remove(IdentityKey.of(sslEngine)); + if (info == null) return; info.setSslSessionDetails(sslEngine.getSession()); }); } @@ -180,6 +190,7 @@ class JettyConnectionLogger extends AbstractLifeCycle implements Connection.List handleListenerInvocation("SslHandshakeListener", "handshakeFailed", "sslEngine=%h,failure=%s", List.of(sslEngine, failure), () -> { log.log(Level.FINE, failure, failure::toString); ConnectionInfo info = sslToConnectionInfo.remove(IdentityKey.of(sslEngine)); + if (info == null) return; info.setSslHandshakeFailure((SSLHandshakeException)failure); }); } -- cgit v1.2.3