injection_points: Clear waiter slot on error and exit
authorMichael Paquier <michael@paquier.xyz>
Thu, 23 Jul 2026 05:37:39 +0000 (14:37 +0900)
committerMichael Paquier <michael@paquier.xyz>
Thu, 23 Jul 2026 05:37:39 +0000 (14:37 +0900)
commita49b6a61094677f75807e452f333f87d4926083f
tree04b4d7b73f1edba783ad13aad4aa7a9db20ba818
parent1a8c172228db9f8ffd7add086e3b0a3cc4986b1c
injection_points: Clear waiter slot on error and exit

injection_wait() only clears its slot in the waiter array after the
wait loop finishes.  When the waiting query is canceled or the backend
is terminated (wait look has a CHECK_FOR_INTERRUPS), the slot leaks.
Later wakeups of the same point then bump the counter of the leaked slot
instead of the real waiter, that sleeps forever.  Repeated leaks can
exhaust all the slots.

The code is changed so as the waiting loop is wrapped with
PG_ENSURE_ERROR_CLEANUP, so as the injection point slots, that are
shared resources, can be cleaned up on ERROR as much as a FATAL.

An isolation test is added: cancel one waiter, terminate another waiter,
then check that a later waiter still receives a wakeup.  Without the
fixed code, the test would fail on timeout.

Author: Zsolt Parragi <zsolt.parragi@percona.com>
Discussion: https://postgr.es/m/CAN4CZFO+KF=cc0-iEg28RhqRBp_fTs6D4b8b7D7DB-pGYP3Ccg@mail.gmail.com
Backpatch-through: 17
src/test/modules/injection_points/Makefile
src/test/modules/injection_points/expected/wait_cleanup.out [new file with mode: 0644]
src/test/modules/injection_points/injection_points.c
src/test/modules/injection_points/meson.build
src/test/modules/injection_points/specs/wait_cleanup.spec [new file with mode: 0644]