RE: Injection point: fix race condition between attach and cleanup

From: "Hayato Kuroda (Fujitsu)" <kuroda(dot)hayato(at)fujitsu(dot)com>
To: "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: "michael(at)paquier(dot)xyz" <michael(at)paquier(dot)xyz>, 'Kyotaro Horiguchi' <horikyota(dot)ntt(at)gmail(dot)com>, "sawada(dot)mshk(at)gmail(dot)com" <sawada(dot)mshk(at)gmail(dot)com>
Subject: RE: Injection point: fix race condition between attach and cleanup
Date: 2026-11-20 12:27:33
Message-ID: OS7PR01MB18317E6F62C793F0474AC1707F5782@OS7PR01MB18317.jpnprd01.prod.outlook.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Michael, Sawada-san and Horiguchi-san,

Thanks for the feedback. OK, let's go ahead to fix the perl module.

My besic idea is to 1) get OID of the backend then 2) do kill(0, $pid) to check
the existence. There were several approaches to get the backend PID to wait for,
I chose to remember the backend PID at wait_connect() and ensure its exit in quit().
This needs additional work for all background sessions but it looks simpler for me.
Another idea I came up with:

* Specify the backend PID by an argument. This can minimize changes on the module
but developers must take care. It may be difficult to make it default.
* Obtain the backend PID in quit(). This must consider the case queries input
before the quit() returns results asynchronously thus stdout/stderr can be
mixture.

0001 implemented the idea and 0002 used it. 0003 patch made sure the waiting is done
by default. Per my quick check, 013_temp_obj_multisession tried to ensure
shmem_cleanup can be blocked, so quit(0) must be used here.

Best regards,
Hayato Kuroda
FUJITSU LIMITED

Attachment Content-Type Size
0001-Allow-BackgroundPsql-quit-to-wait-for-backend-exit.patch application/octet-stream 2.9 KB
0002-Use-BackgroundPsql-quit-1-to-wait-for.patch application/octet-stream 6.5 KB
0003-Wait-for-backend-exit-by-default-in-BackgroundPsql-q.patch application/octet-stream 5.0 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Vaibhav Dalvi 2026-11-20 12:27:36 Re: walreceiver: stale hot_standby_feedback xmin on primary when wal_receiver_status_interval = 0 (PG16 and later)
Previous Message Xuneng Zhou 2026-11-20 12:26:02 Re: [BUG] Take a long time to reach consistent after pg_rewind