pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Heikki Linnakangas <heikki.linnakangas@iki.fi>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Move cancel key generation to after forking the backend
Date: Mon, 29 Jul 2024 13:18:14 +0000
Message-ID: <E1sYQGU-001kL9-BT@gemulon.postgresql.org> (raw)

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(-)



view thread (5+ messages)  latest in thread

Message-ID: <E1sYQGU-001kL9-BT@gemulon.postgresql.org>
Permalink:  ../E1sYQGU-001kL9-BT@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1sYQGU-001kL9-BT@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: heikki.linnakangas@iki.fi, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Move cancel key generation to after forking the backend
  In-Reply-To: <E1sYQGU-001kL9-BT@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox