Re: [HACKERS] PoC: custom signal handler for extensions

From: Arthur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
To: Maksim Milyutin <milyutinma(at)gmail(dot)com>
Cc: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] PoC: custom signal handler for extensions
Date: 2018-01-11 15:53:49
Message-ID: 20180111155348.GA25847@zakirov.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello,

On Fri, Dec 22, 2017 at 03:05:25PM +0300, Maksim Milyutin wrote:
> Hi, hackers!
>
>
> I want to propose the patch that allows to define custom signals and their
> handlers on extension side.
>

I've looked a little bit on the patch. The patch applyes and regression tests pass.
I have a couple comments.

> The relationship between custom signals and
> assigned handlers (function addresses) is replicated from postmaster to
> child processes including working backends.

I think this happens only if a custom signal registered during initializing shared_preload_libraries.
But from RegisterCustomProcSignalHandler()'s implementation I see that you can register the signal anytime. Am I wrong?

If so then custom signal handlers may not work as expected.

What is purpose of AssignCustomProcSignalHandler() function? This function can erase a handler set by another extension.
For example, extension 1 set handler passing reason PROCSIG_CUSTOM_1, and extension 2 set another handler passing reason PROCSIG_CUSTOM_1 too. Here the handler of the extension 2 will be purged.

> +
> + Assert(reason >= PROCSIG_CUSTOM_1 && reason <= PROCSIG_CUSTOM_N);
> +

I think it is not good to use asserts within AssignCustomProcSignalHandler() and GetCustomProcSignalHandler(). Because this functions can be executed by an external extension, and it may pass a reason outside this boundary. It will be better if the reason will be checked in runtime.

But it is fine for this assert within CustomSignalInterrupt().

--
Arthur Zakirov
Postgres Professional: http://www.postgrespro.com
Russian Postgres Company

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2018-01-11 15:55:21 Re: CUBE seems a bit confused about ORDER BY
Previous Message Ildar Musin 2018-01-11 15:53:22 Re: General purpose hashing func in pgbench