pgsql: injection_points: Fix race condition with local injection point

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: injection_points: Fix race condition with local injection point
Date: 2024-04-09 01:31:52
Message-ID: E1ru0L1-001DhD-Rc@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

injection_points: Fix race condition with local injection point tests

The module relies on a shmem exit callback to clean up any injection
points linked to a specific process. One of the tests checks for the
case of an injection point name reused in a second connection where the
first connection should clean it up, but it did not count for the fact
that the shmem exit callback of the first connection may not have run
when the second connection begins its work.

The regress library includes a wait_pid() that can be used for this
purpose, instead of a custom wait logic, so let's rely on it to wait for
the first connection to exit before working with the second connection.
The module gains a REGRESS_OPTS to be able to look at the regress
library's dlpath.

This issue could be reproduced with a hardcoded sleep() in the shmem
exit callback, and the CI has been able to trigger it sporadically.

Oversight in f587338dec87.

Reported-by: Bharath Rupireddy
Reviewed-by: Andrey Borodin
Discussion: https://postgr.es/m/ZhOd3NXAutteokGL@paquier.xyz

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/f4083c49751018ae2140de8bf752b8d60485a6ca

Modified Files
--------------
src/test/modules/injection_points/Makefile | 1 +
.../injection_points/expected/injection_points.out | 17 +++++++++++++++++
src/test/modules/injection_points/meson.build | 1 +
.../modules/injection_points/sql/injection_points.sql | 16 ++++++++++++++++
4 files changed, 35 insertions(+)

Browse pgsql-committers by date

  From Date Subject
Next Message Kyotaro Horiguchi 2024-04-09 01:46:13 Re: pgsql: With gssencmode='require', check credential cache before connect
Previous Message Tom Lane 2024-04-08 21:00:16 pgsql: In psql, avoid leaking a PGresult after a query is cancelled.