Skip to content

Commit 39f0ef6

Browse files
zasweqmenghanl
authored andcommitted
[v1.41.x_backport] transport: fix log spam from Server Authentication Handshake errors (grpc#4798)
* transport: fix log spam from Server Authentication Handshake errors
1 parent 8c8b55e commit 39f0ef6

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

internal/transport/http2_server.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,11 @@ func NewServerTransport(conn net.Conn, config *ServerConfig) (_ ServerTransport,
139139
var err error
140140
conn, authInfo, err = config.Credentials.ServerHandshake(rawConn)
141141
if err != nil {
142-
// ErrConnDispatched means that the connection was dispatched away from
143-
// gRPC; those connections should be left open.
144-
if err == credentials.ErrConnDispatched {
142+
// ErrConnDispatched means that the connection was dispatched away
143+
// from gRPC; those connections should be left open. io.EOF means
144+
// the connection was closed before handshaking completed, which can
145+
// happen naturally from probers. Return these errors directly.
146+
if err == credentials.ErrConnDispatched || err == io.EOF {
145147
return nil, err
146148
}
147149
return nil, connectionErrorf(false, err, "ServerHandshake(%q) failed: %v", rawConn.RemoteAddr(), err)

server.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,12 @@ func (s *Server) newHTTP2Transport(c net.Conn) transport.ServerTransport {
887887
if err != credentials.ErrConnDispatched {
888888
c.Close()
889889
}
890-
channelz.Warning(logger, s.channelzID, "grpc: Server.Serve failed to create ServerTransport: ", err)
890+
// Don't log on ErrConnDispatched and io.EOF to prevent log spam.
891+
if err != credentials.ErrConnDispatched {
892+
if err != io.EOF {
893+
channelz.Warning(logger, s.channelzID, "grpc: Server.Serve failed to create ServerTransport: ", err)
894+
}
895+
}
891896
return nil
892897
}
893898

0 commit comments

Comments
 (0)