mirror of
https://github.com/postgres/postgres.git
synced 2025-11-04 20:11:56 +03:00
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
This commit is contained in:
@@ -48,7 +48,8 @@ pg_time_t MyStartTime;
|
||||
TimestampTz MyStartTimestamp;
|
||||
struct ClientSocket *MyClientSocket;
|
||||
struct Port *MyProcPort;
|
||||
int32 MyCancelKey;
|
||||
bool MyCancelKeyValid = false;
|
||||
int32 MyCancelKey = 0;
|
||||
int MyPMChildSlot;
|
||||
|
||||
/*
|
||||
|
||||
@@ -683,7 +683,7 @@ InitPostgres(const char *in_dbname, Oid dboid,
|
||||
*/
|
||||
SharedInvalBackendInit(false);
|
||||
|
||||
ProcSignalInit();
|
||||
ProcSignalInit(MyCancelKeyValid, MyCancelKey);
|
||||
|
||||
/*
|
||||
* Also set up timeout handlers needed for backend operation. We need
|
||||
|
||||
Reference in New Issue
Block a user