Skip to content

pgwire: send BackendKeyData message for pgpool compatibility #13009

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
16 changes: 16 additions & 0 deletions pkg/sql/pgwire/v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const (
clientMsgTerminate clientMessageType = 'X'

serverMsgAuth serverMessageType = 'R'
serverMsgBackendKeyData serverMessageType = 'K'
serverMsgBindComplete serverMessageType = '2'
serverMsgCommandComplete serverMessageType = 'C'
serverMsgCloseComplete serverMessageType = '3'
Expand Down Expand Up @@ -340,6 +341,21 @@ func (c *v3Conn) serve(ctx context.Context, reserved mon.BoundAccount) error {
c.conn = newReadTimeoutConn(c.conn, c.session.Ctx().Err)
c.rd = bufio.NewReader(c.conn)

// Send the client a dummy BackendKeyData message. This is necessary for
// compatibility with pgpool, a popular third-party load balancer.
// This information is normally used by clients to send a CancelRequest
// message:
// https://www.postgresql.org/docs/9.6/static/protocol-flow.html#AEN112861
c.writeBuf.initMsg(serverMsgBackendKeyData)
c.writeBuf.putInt32(0)
c.writeBuf.putInt32(0)
if err := c.writeBuf.finishMsg(c.wr); err != nil {
return err
}
if err := c.wr.Flush(); err != nil {
return err
}

for {
if !c.doingExtendedQueryMessage {
c.writeBuf.initMsg(serverMsgReady)
Expand Down