Parsed test spec with 2 sessions starting permutation: s1-register s2-lock s1-lock s2-wrong-cancel-1 s2-wrong-cancel-2 s2-cancel step s1-register: INSERT INTO cancel_table VALUES (pg_backend_pid(), get_cancellation_key()); step s2-lock: BEGIN; LOCK TABLE cancel_table IN ACCESS EXCLUSIVE MODE; step s1-lock: BEGIN; LOCK TABLE cancel_table IN ACCESS EXCLUSIVE MODE; END; step s2-wrong-cancel-1: SELECT run_pg_send_cancellation(pid + 1, cancel_key) FROM cancel_table; run_pg_send_cancellation --------------------------------------------------------------------- (1 row) step s2-wrong-cancel-2: SELECT run_pg_send_cancellation(pid, cancel_key + 1) FROM cancel_table; run_pg_send_cancellation --------------------------------------------------------------------- (1 row) step s2-cancel: SELECT run_pg_send_cancellation(pid, cancel_key) FROM cancel_table; END; run_pg_send_cancellation --------------------------------------------------------------------- (1 row) step s1-lock: <... completed> ERROR: canceling statement due to user request