@@ -41,6 +41,9 @@ private[netty4] class SslServerVerificationHandler(
4141 private [this ] val onHandshakeComplete = Promise [Unit ]()
4242 private [this ] val sslExceptionStats = statsReceiver.scope(" ssl_exn" )
4343
44+ private [this ] val NoPeerCert = " no_peer_cert"
45+ private [this ] val Unknown = " unknown"
46+
4447 private [this ] def verifySession (session : SSLSession , ctx : ChannelHandlerContext ): Unit = {
4548 // Clean up ThreadLocal immediately for successful handshakes
4649 // This prevents leaking the service identifier to subsequent requests on the same thread
@@ -103,24 +106,21 @@ private[netty4] class SslServerVerificationHandler(
103106 }
104107
105108 // No certificate available
106- Some (" no_peer_cert " )
109+ Some (NoPeerCert )
107110 }
108111
109112 private [this ] def trackHandshakeFailure (cause : Throwable ): Unit = {
110- val serviceId = extractServiceIdentifier().getOrElse(" unknown " )
113+ val serviceId = extractServiceIdentifier().getOrElse(Unknown )
111114 // Sanitize service identifier for use in metric names
112115 val sanitized = serviceId.replaceAll(" [^a-zA-Z0-9:_-]" , " _" )
113116
114- // Log every time we increment the counter to debug potential double-counting
115- log.warning(
116- s " Incrementing ssl_exn counter for service ' $serviceId' from $remoteAddress: ${cause.getClass.getSimpleName}: ${cause.getMessage}" )
117+ if (serviceId != NoPeerCert && serviceId != Unknown ) {
118+ // Log every time we increment the counter to debug potential double-counting
119+ log.warning(
120+ s " Incrementing ssl_exn counter for service ' $serviceId' from $remoteAddress: ${cause.getClass.getSimpleName}: ${cause.getMessage}" )
121+ }
117122
118123 sslExceptionStats.counter(sanitized).incr()
119-
120- if (log.isLoggable(Level .DEBUG )) {
121- log.debug(
122- s " SSL handshake failed for service identifier ' $serviceId' from $remoteAddress: ${cause.getMessage}" )
123- }
124124 }
125125
126126 override def handlerAdded (ctx : ChannelHandlerContext ): Unit = {
0 commit comments