pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jehan-Guillaume de Rorthais <jgdr@dalibo.com>
To: Alvaro Herrera <alvherre@2ndquadrant.com>
Cc: Michael Paquier <michael@paquier.xyz>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: [BUG v13] Crash with event trigger in extension
Date: Tue, 8 Sep 2020 19:07:59 +0200
Message-ID: <20200908190759.12405fe5@firost> (raw)
In-Reply-To: <20200908143324.GA11045@alvherre.pgsql>
References: <20200908161511.3e340588@firost>
	<20200908143324.GA11045@alvherre.pgsql>

On Tue, 8 Sep 2020 11:33:24 -0300
Alvaro Herrera <alvherre@2ndquadrant.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,





view thread (21+ messages)  latest in thread

Message-ID: <20200908190759.12405fe5@firost>
Permalink:  ../20200908190759.12405fe5@firost/
Also on:    postgresql.org/message-id/20200908190759.12405fe5@firost

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: jgdr@dalibo.com, alvherre@2ndquadrant.com, michael@paquier.xyz, pgsql-bugs@lists.postgresql.org
  Subject: Re: [BUG v13] Crash with event trigger in extension
  In-Reply-To: <20200908190759.12405fe5@firost>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox