pgsql: Move cancel key generation to after forking the backend

From: Heikki Linnakangas <heikki(dot)linnakangas(at)iki(dot)fi>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Move cancel key generation to after forking the backend
Date: 2024-07-29 13:18:14
Message-ID: E1sYQGU-001kL9-BT@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Move cancel key generation to after forking the backend

Move responsibility of generating the cancel key to the backend
process. The cancel key is now generated after forking, and the
backend advertises it in the ProcSignal array. When a cancel request
arrives, the backend handling it scans the ProcSignal array to find
the target pid and cancel key. This is similar to how this previously
worked in the EXEC_BACKEND case with the ShmemBackendArray, just
reusing the ProcSignal array.

One notable change is that we no longer generate cancellation keys for
non-backend processes. We generated them before just to prevent a
malicious user from canceling them; the keys for non-backend processes
were never actually given to anyone. There is now an explicit flag
indicating whether a process has a valid key or not.

I wrote this originally in preparation for supporting longer cancel
keys, but it's a nice cleanup on its own.

Reviewed-by: Jelte Fennema-Nio
Discussion: https://www.postgresql.org/message-id/508d0505-8b7a-4864-a681-e7e5edfe32aa@iki.fi

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/9d9b9d46f3c509c722ebbf2a1e7dc6296a6c711d

Modified Files
--------------
src/backend/postmaster/auxprocess.c | 2 +-
src/backend/postmaster/launch_backend.c | 10 +-
src/backend/postmaster/postmaster.c | 196 +-------------------------------
src/backend/storage/ipc/ipci.c | 11 --
src/backend/storage/ipc/procsignal.c | 185 +++++++++++++++++++++++-------
src/backend/tcop/backend_startup.c | 9 +-
src/backend/tcop/postgres.c | 17 +++
src/backend/utils/init/globals.c | 3 +-
src/backend/utils/init/postinit.c | 2 +-
src/include/miscadmin.h | 1 +
src/include/postmaster/postmaster.h | 9 --
src/include/storage/procsignal.h | 10 +-
12 files changed, 193 insertions(+), 262 deletions(-)

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Daniel Gustafsson 2024-07-29 13:23:06 Re: pgsql: Move cancel key generation to after forking the backend
Previous Message Heikki Linnakangas 2024-07-29 11:27:11 pgsql: Fix outdated comment in smgrtruncate()