]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Handle cancel requests with PID 0 gracefully
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Tue, 29 Jul 2025 21:39:49 +0000 (00:39 +0300)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Tue, 29 Jul 2025 21:39:49 +0000 (00:39 +0300)
If the client sent a query cancel request with backend PID 0, it
tripped an assertion. With assertions disabled, you got this in the
log instead:

    LOG:  invalid cancel request with PID 0
    LOG:  wrong key in cancel request for process 0

Query cancellations don't even require authentication, so we better
tolerate bogus requests. Fix by turning the assertion into a regular
runtime check.

Spotted while testing libpq behavior with a modified server that
didn't send BackendKeyData to the client.

Backpatch-through: 18

src/backend/storage/ipc/procsignal.c

index a9bb540b55ac2c976b7d74232598347c126578e9..087821311cceb4d0445aa341b7d7d924fc703fec 100644 (file)
@@ -728,7 +728,11 @@ procsignal_sigusr1_handler(SIGNAL_ARGS)
 void
 SendCancelRequest(int backendPID, const uint8 *cancel_key, int cancel_key_len)
 {
-       Assert(backendPID != 0);
+       if (backendPID == 0)
+       {
+               ereport(LOG, (errmsg("invalid cancel request with PID 0")));
+               return;
+       }
 
        /*
         * See if we have a matching backend. Reading the pss_pid and