Re: [BUG v13] Crash with event trigger in extension

From: Jehan-Guillaume de Rorthais <jgdr(at)dalibo(dot)com>
To: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: [BUG v13] Crash with event trigger in extension
Date: 2020-09-08 17:07:59
Message-ID: 20200908190759.12405fe5@firost
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Tue, 8 Sep 2020 11:33:24 -0300
Alvaro Herrera <alvherre(at)2ndquadrant(dot)com> wrote:

> On 2020-Sep-08, Jehan-Guillaume de Rorthais wrote:
>
> > It appears that when keeping the event trigger enabled,
> > currentEventTriggerState might be initiated multiple times: one for the top
> > level "alter extension ... update", then once per DDL query triggering en
> > event in the extension update script. I suppose there's no crash because
> > the very first currentEventTriggerState initialized at top level is
> > overrode by next ones, each being destroyed in their own context. So at the
> > end of the extension script, currentEventTriggerState is just destroyed and
> > empty.
>
> Hmm. I spent a lot of time making sure the event trigger thing worked
> correctly in reentrant cases, but I don't think the case of execution of
> extension scripts was ever considered. So you're right that it might be
> broken, since it appears not to be thoroughly tested (if at all).

Argh. After some more debugging, I realized I missed the fact that
EventTriggerBeginCompleteQuery/EventTriggerEndCompleteQuery were actually
stacking allocations using currentEventTriggerState->previous. My bad, sorry for
your time.

I still have a last question in mind though. While running the bellow
scenario, the DDL in the extension do not trigger evt_ext_ddl_fnct. Is it
normal/expected?

BEGIN;
CREATE OR REPLACE FUNCTION _evt_ext_ddl_fnct()
RETURNS EVENT_TRIGGER LANGUAGE plpgsql AS
$$
DECLARE r record;
BEGIN
FOR r in SELECT * FROM pg_event_trigger_ddl_commands() LOOP
raise notice 'called %: %.%',
quote_ident(r.command_tag),
quote_ident(r.schema_name),
quote_ident(r.object_identity);
end loop;
END;
$$;

CREATE EVENT TRIGGER evt_ext_ddl_fnct
ON ddl_command_end
EXECUTE PROCEDURE _evt_ext_ddl_fnct();

CREATE EXTENSION test_event_trigger VERSION '1.0';
ALTER EXTENSION test_event_trigger UPDATE TO '2.0';

CREATE TABLE test( i int);
ROLLBACK;

The only output is:

NOTICE: called "CREATE EXTENSION": <NULL>.test_event_trigger
NOTICE: called "ALTER EXTENSION": <NULL>.test_event_trigger
NOTICE: called "CREATE TABLE": public."public.test"

Regards,

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Alvaro Herrera 2020-09-08 17:32:22 Re: [BUG v13] Crash with event trigger in extension
Previous Message Peter Eisentraut 2020-09-08 14:36:23 Re: BUG #15285: Query used index over field with ICU collation in some cases wrongly return 0 rows