Skip to content

Commit 8059a81

Browse files
authored
Merge pull request #155658 from rafiss/backport25.4-154916-155656
release-25.4: pgwire: make max repeated error count configurable via cluster setting
2 parents 0c6f471 + 5b51f74 commit 8059a81

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

pkg/sql/pgwire/conn_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,8 +1449,11 @@ func TestConnServerAbortsOnRepeatedErrors(t *testing.T) {
14491449
conn, err := db.Conn(ctx)
14501450
require.NoError(t, err)
14511451

1452+
// Get the current value of the cluster setting.
1453+
maxErrors := int(maxRepeatedErrorCount.Get(&srv.ClusterSettings().SV))
1454+
14521455
atomic.StoreUint32(&shouldError, 1)
1453-
for i := 0; i < maxRepeatedErrorCount+100; i++ {
1456+
for i := 0; i < maxErrors+100; i++ {
14541457
var s int
14551458
err := conn.QueryRowContext(ctx, "SELECT 1").Scan(&s)
14561459
if err != nil {
@@ -1459,9 +1462,9 @@ func TestConnServerAbortsOnRepeatedErrors(t *testing.T) {
14591462
}
14601463
if errors.Is(err, driver.ErrBadConn) {
14611464
// The server closed the connection, which is what we want!
1462-
require.GreaterOrEqualf(t, i, maxRepeatedErrorCount,
1465+
require.GreaterOrEqualf(t, i, maxErrors,
14631466
"the server should have aborted after seeing %d errors",
1464-
maxRepeatedErrorCount,
1467+
maxErrors,
14651468
)
14661469
return
14671470
}

pkg/sql/pgwire/server.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,15 @@ var logVerboseSessionAuth = settings.RegisterBoolSetting(
9494
false,
9595
settings.WithPublic)
9696

97+
var maxRepeatedErrorCount = settings.RegisterIntSetting(
98+
settings.ApplicationLevel,
99+
"sql.pgwire.max_repeated_error_count",
100+
"the maximum number of times an error can be received while reading from a "+
101+
"network connection before the server aborts the connection",
102+
1<<15, // 32768
103+
settings.PositiveInt,
104+
)
105+
97106
const (
98107
// ErrSSLRequired is returned when a client attempts to connect to a
99108
// secure server in cleartext.
@@ -1072,11 +1081,6 @@ func (s *Server) newConn(
10721081
return c
10731082
}
10741083

1075-
// maxRepeatedErrorCount is the number of times an error can be received
1076-
// while reading from the network connection before the server decides to give
1077-
// up and abort the connection.
1078-
const maxRepeatedErrorCount = 1 << 15
1079-
10801084
// serveImpl continuously reads from the network connection and pushes execution
10811085
// instructions into a sql.StmtBuf, from where they'll be processed by a command
10821086
// "processor" goroutine (a connExecutor).
@@ -1448,7 +1452,7 @@ func (s *Server) serveImpl(
14481452
// 3. we reached an arbitrary threshold of repeated errors.
14491453
if netutil.IsClosedConnection(err) ||
14501454
errors.Is(err, context.Canceled) ||
1451-
repeatedErrorCount > maxRepeatedErrorCount {
1455+
repeatedErrorCount > int(maxRepeatedErrorCount.Get(&s.execCfg.Settings.SV)) {
14521456
break
14531457
}
14541458
} else {

0 commit comments

Comments
 (0)