diff --git a/pkg/sql/pgwire/conn_test.go b/pkg/sql/pgwire/conn_test.go index b499bbf6f541..38c4b9613bb2 100644 --- a/pkg/sql/pgwire/conn_test.go +++ b/pkg/sql/pgwire/conn_test.go @@ -1449,8 +1449,11 @@ func TestConnServerAbortsOnRepeatedErrors(t *testing.T) { conn, err := db.Conn(ctx) require.NoError(t, err) + // Get the current value of the cluster setting. + maxErrors := int(maxRepeatedErrorCount.Get(&srv.ClusterSettings().SV)) + atomic.StoreUint32(&shouldError, 1) - for i := 0; i < maxRepeatedErrorCount+100; i++ { + for i := 0; i < maxErrors+100; i++ { var s int err := conn.QueryRowContext(ctx, "SELECT 1").Scan(&s) if err != nil { @@ -1459,9 +1462,9 @@ func TestConnServerAbortsOnRepeatedErrors(t *testing.T) { } if errors.Is(err, driver.ErrBadConn) { // The server closed the connection, which is what we want! - require.GreaterOrEqualf(t, i, maxRepeatedErrorCount, + require.GreaterOrEqualf(t, i, maxErrors, "the server should have aborted after seeing %d errors", - maxRepeatedErrorCount, + maxErrors, ) return } diff --git a/pkg/sql/pgwire/server.go b/pkg/sql/pgwire/server.go index 826699c445da..ce15e8821fc7 100644 --- a/pkg/sql/pgwire/server.go +++ b/pkg/sql/pgwire/server.go @@ -94,6 +94,15 @@ var logVerboseSessionAuth = settings.RegisterBoolSetting( false, settings.WithPublic) +var maxRepeatedErrorCount = settings.RegisterIntSetting( + settings.ApplicationLevel, + "sql.pgwire.max_repeated_error_count", + "the maximum number of times an error can be received while reading from a "+ + "network connection before the server aborts the connection", + 1<<8, // 256 + settings.PositiveInt, +) + const ( // ErrSSLRequired is returned when a client attempts to connect to a // secure server in cleartext. @@ -1079,11 +1088,6 @@ func (s *Server) newConn( return c } -// maxRepeatedErrorCount is the number of times an error can be received -// while reading from the network connection before the server decides to give -// up and abort the connection. -const maxRepeatedErrorCount = 1 << 8 - // serveImpl continuously reads from the network connection and pushes execution // instructions into a sql.StmtBuf, from where they'll be processed by a command // "processor" goroutine (a connExecutor). @@ -1455,7 +1459,7 @@ func (s *Server) serveImpl( // 3. we reached an arbitrary threshold of repeated errors. if netutil.IsClosedConnection(err) || errors.Is(err, context.Canceled) || - repeatedErrorCount > maxRepeatedErrorCount { + repeatedErrorCount > int(maxRepeatedErrorCount.Get(&s.execCfg.Settings.SV)) { break } } else {