Skip to content

Commit

Permalink
Merge #76476
Browse files Browse the repository at this point in the history
76476: sql/pgwire: close cancel request conn as soon as possible r=otan a=rafiss

fixes #76231

Rather than closing in the defer block, do it sooner. This is because
some clients (e.g. PGJDBC) rely on timeout behavior where the connection
is closed as soon as the request data is read.

Release note: None

Co-authored-by: Rafi Shamim <rafi@cockroachlabs.com>
  • Loading branch information
craig[bot] and rafiss committed Feb 14, 2022
2 parents 7bc4b4f + bff48f6 commit bbb473c
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions pkg/sql/pgwire/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -747,16 +747,15 @@ func (s *Server) handleCancel(ctx context.Context, conn net.Conn, buf *pgwirebas
log.Sessions.Warningf(ctx, "unexpected while handling pgwire cancellation request: %v", err)
}
telemetry.Inc(sqltelemetry.CancelRequestCounter)

// The connection that issued the cancel is not a SQL session -- it's an
// entirely new connection that's created just to send the cancel. There
// isn't anything left for the server to do after it handles the
// pgwire cancel request.
_ = conn.Close()
}()

var backendKeyDataBits uint64
backendKeyDataBits, err = buf.GetUint64()
// The connection that issued the cancel is not a SQL session -- it's an
// entirely new connection that's created just to send the cancel. We close
// the connection as soon as possible after reading the data, since there
// is nothing to send back to the client.
_ = conn.Close()
if err != nil {
return
}
Expand Down

0 comments on commit bbb473c

Please sign in to comment.