Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kFh6G-0005bG-49 for pgsql-bugs@arkaria.postgresql.org; Tue, 08 Sep 2020 17:08:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kFh6F-0008Gb-2P for pgsql-bugs@arkaria.postgresql.org; Tue, 08 Sep 2020 17:08:07 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kFh6E-0008GU-HZ for pgsql-bugs@lists.postgresql.org; Tue, 08 Sep 2020 17:08:06 +0000 Received: from mail.dalibo.com ([212.85.157.172]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kFh6C-00011t-5N for pgsql-bugs@lists.postgresql.org; Tue, 08 Sep 2020 17:08:05 +0000 Received: from firost (larco.ioguix.net [82.66.0.6]) by mail.dalibo.com (Postfix) with ESMTPSA id 73CCF2044C; Tue, 8 Sep 2020 19:08:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=dalibo.com; s=a; t=1599584880; bh=25TZ24y9TK4O77hbGGGNQBps3rhCm0ee5aCOu+SDAdQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=LwfWaqApimWhE8Q5BXUa88raTqf5tTNyEPVvkGkIJI4GERi/dB/LTBYMAnbl0ZI0+ ajtwkSr5KT9BJF4MAxGAGq/kP2DDMXcmjDSKc6REvq8OeW/lPggsrVSUxcmu0oKYvo VsD67pdqvo+caaxQ5HEpd89e8LIW3lVkw2Sm9XC8= Date: Tue, 8 Sep 2020 19:07:59 +0200 From: Jehan-Guillaume de Rorthais To: Alvaro Herrera Cc: Michael Paquier , pgsql-bugs@lists.postgresql.org Subject: Re: [BUG v13] Crash with event trigger in extension Message-ID: <20200908190759.12405fe5@firost> In-Reply-To: <20200908143324.GA11045@alvherre.pgsql> References: <20200908161511.3e340588@firost> <20200908143324.GA11045@alvherre.pgsql> Organization: Dalibo MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Tue, 8 Sep 2020 11:33:24 -0300 Alvaro Herrera 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": .test_event_trigger NOTICE: called "ALTER EXTENSION": .test_event_trigger NOTICE: called "CREATE TABLE": public."public.test" Regards,