Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions pkg/sql/pgwire/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down
16 changes: 10 additions & 6 deletions pkg/sql/pgwire/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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 {
Expand Down
Loading