Skip to content

Commit 2acab5d

Browse files
committed
pgwire: limit the number of connection error logs
Rejecting new connections while server is draining printed too many logs, making it difficult to spot other errors during drain. Added a EveryN log to limit the log frequency to every 10 seconds. Fixes #102339 Release note: None
1 parent a09dc3c commit 2acab5d

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

pkg/sql/pgwire/server.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,8 @@ type Server struct {
309309
// destinations tracks the metrics for each destination.
310310
destinations map[string]*destinationMetrics
311311
}
312+
// limit the number of rejectNewConnection errors
313+
connectionErrorLogEveryN log.EveryN
312314

313315
auth struct {
314316
syncutil.RWMutex
@@ -490,6 +492,7 @@ func MakeServer(
490492
server.mu.drainCh = make(chan struct{})
491493
server.mu.destinations = make(map[string]*destinationMetrics)
492494
server.mu.Unlock()
495+
server.connectionErrorLogEveryN = log.Every(10 * time.Second)
493496
executorConfig.CidrLookup.SetOnChange(server.onCidrChange)
494497

495498
connAuthConf.SetOnChange(&st.SV, func(ctx context.Context) {
@@ -931,7 +934,9 @@ func (s *Server) ServeConn(
931934
st := s.execCfg.Settings
932935
// If the server is shutting down, terminate the connection early.
933936
if rejectNewConnections {
934-
log.Ops.Info(ctx, "rejecting new connection while server is draining")
937+
if s.connectionErrorLogEveryN.ShouldLog() {
938+
log.Ops.Info(ctx, "rejecting new connection while server is draining")
939+
}
935940
return s.sendErr(ctx, st, conn, newAdminShutdownErr(ErrDrainingNewConn))
936941
}
937942

0 commit comments

Comments
 (0)