Skip to content

Commit 7005fb9

Browse files
joannayliujenkins
authored andcommitted
Remove peer cert log errors if no service identifier is available
Differential Revision: https://phabricator.twitter.biz/D1324267
1 parent cd93f76 commit 7005fb9

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

finagle-netty4/src/main/scala/com/twitter/finagle/netty4/ssl/server/SslServerVerificationHandler.scala

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)