Skip to content

Commit

Permalink
sql/pgwire: close cancel request conn as soon as possible
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rafiss committed Feb 12, 2022
1 parent 657c0e1 commit bff48f6
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 bff48f6

Please sign in to comment.