Re: BackendKeyData is mandatory?
Heikki Linnakangas <hlinnaka@iki.fi>
From: Heikki Linnakangas <hlinnaka@iki.fi>
To: Jelte Fennema-Nio <postgres@jeltef.nl>
Cc: Tom Lane <tgl@sss.pgh.pa.us>,
Jacob Champion <jacob.champion@enterprisedb.com>,
Tatsuo Ishii <ishii@postgresql.org>, peter@eisentraut.org,
pgsql-hackers@postgresql.org, Dave Cramer <davecramer@gmail.com>
Date: 2025-08-14T13:10:51Z
Lists: pgsql-hackers
Attachments
- v4-0001-libpq-Don-t-hang-on-out-of-memory.patch (text/x-patch) patch v4-0001
- v4-0002-libpq-Handle-OOMs-by-disconnecting-instead-of-sil.patch (text/x-patch) patch v4-0002
- v4-0003-libpq-Be-strict-about-cancel-key-lengths.patch (text/x-patch) patch v4-0003
On 11/08/2025 09:58, Jelte Fennema-Nio wrote: > On Fri, 8 Aug 2025 at 17:50, Heikki Linnakangas <hlinnaka@iki.fi> wrote: >> I think any of the other options would be >> better. There's no guarantee that more data will ever arrive, the >> connection might be used just to wait for the notification. > > Yeah, I think that's the important thing to realize here. The "try > again later" only makes sense if we need more data to try again. If we > don't then we now start waiting on data that might never come. Here's a new set of patches, to disconnect on OOM instead of hanging or silently discarding messages: v4-0001-libpq-Don-t-hang-on-out-of-memory.patch This is a very minimal fix for the "hang on OOM" issue. It changes the behavior to silently skip over the message, i.e. discard the async notification, or continue without cancellation key. I think we should backpatch this. v4-0002-libpq-Handle-OOMs-by-disconnecting-instead-of-sil.patch This changes the behavior of all of the problematic places where we silently discarded things on OOM to disconnect instead. That is, when processing a Notify, BackendKeyData, or ParameterStatus message. Now that I look at this again, we should probably forget about patch #1 and commit and backpatch this straight away. It's a little more changes than patch #1, but not that much. Note that there are still places where we discard things on OOM, like when parsing an error 'E' message. Those are a little iffy too, but they're less problematic because you still get an error, and the error is clearly associated with a query, unlike these Notify, BackendData and ParameterStatus messages. v4-0003-libpq-Be-strict-about-cancel-key-lengths.patch Your patch to add more checks, rebased over the first two. - Heikki
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