Handle cancel requests with PID 0 gracefully

Heikki Linnakangas <heikki.linnakangas@iki.fi>

Commit: fce7da1e73853b21a8084e645ac39354c1476261
Author: Heikki Linnakangas <heikki.linnakangas@iki.fi>
Date: 2025-07-29T21:40:15Z
Releases: 18.0
Handle cancel requests with PID 0 gracefully

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

Files

PathChange+/−
src/backend/storage/ipc/procsignal.c modified +5 −1