Re: BackendKeyData is mandatory?
Jacob Champion <jacob.champion@enterprisedb.com>
From: Jacob Champion <jacob.champion@enterprisedb.com>
To: Jelte Fennema-Nio <postgres@jeltef.nl>
Cc: Tatsuo Ishii <ishii@postgresql.org>, tgl@sss.pgh.pa.us, hlinnaka@iki.fi, peter@eisentraut.org, pgsql-hackers@postgresql.org
Date: 2025-06-30T17:58:53Z
Lists: pgsql-hackers
On Wed, Jun 25, 2025 at 12:12 AM Jelte Fennema-Nio <postgres@jeltef.nl> wrote:
> Attached is an attempt at implementing the above. I did not test it
> against these systems though.
With 0001, psycopg2 appears to function again when talking to a server
that doesn't send a cancellation key, so that's good.
It looks like Heikki has an open item for this, so I'll defer to him
for copyediting preferences around the comments and commit messages. I
do have a problem with this part of the new documentation:
+ [...] If no
+ BackendKeyData is sent by the server, then that means that the backend
+ does not support canceling queries using the CancelRequest messages.
I don't think we really know that it means that, yet. I'd prefer something like
Beginning with PostgreSQL 18, libpq assumes that servers do not
support query cancellation if they do not send BackendKeyData.
in the hope that either anyone affected will complain at us to revert,
or it'll become the de facto meaning after some time.
> I also added small commit that checks for the 256 byte key length limit
> described in the protocol documentation. This thread made me remember
> that we talked about that during PGConf.dev.
0002 seems to result in a connection hang if the server sends a bigger
key. I think this may be a latent bug in the original patch -- if
getBackendKeyData() fails, no effort is made to clean up state or
manage the connection buffer. We just... return.
Also, what should we do if the server sends a zero-length key?
Thanks,
--Jacob
Commits
-
Revert unnecessary check for NULL
- 5a26a3e4eeb2 18.0 landed
- 807ee417e562 19 (unreleased) landed
-
libpq: Be strict about cancel key lengths
- e7ff96853ea7 18.0 landed
- e411a8d25a4b 19 (unreleased) landed
-
libpq: Handle OOM by disconnecting instead of hanging or skipping msgs
- 8aa287c9061b 18.0 landed
- f6f0542266f0 19 (unreleased) landed
-
libpq: Complain about missing BackendKeyData later with PGgetCancel()
- 42b1480eb2c6 18.0 landed
- a4801eb691ed 19 (unreleased) landed