Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/tleextension.c
Original file line number Diff line number Diff line change
Expand Up @@ -3976,6 +3976,27 @@ _PU_HOOK
bool cmd_done = false;
Oid tleExtensionOid;

/*
* Explicitly skip TransactionStmts before calling get_extension_oid().
*
* In an aborted transaction, TransactionStmts (e.g. ROLLBACK) will still
* be passed to process utility hooks. However, relcache lookup must be
* done in a transaction state. Because we don't handle TransactionStmts
* in this hook anyway, TransactionStmts can be skipped.
*/
if (pu_parsetree && IsA(pu_parsetree, TransactionStmt))
{
if (prev_hook)
{
_prev_hook;
}
else
{
_standard_ProcessUtility;
}
Comment on lines +3989 to +3996
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nonblocking comment, given it's written otherwise further down on the function, but a future refactor could simplify this to:

Suggested change
if (prev_hook)
{
_prev_hook;
}
else
{
_standard_ProcessUtility;
}
if (prev_hook)
_prev_hook;
else
_standard_ProcessUtility;

return;
}

/*
* We should only execute this hook if the pg_tle extension is installed.
*/
Expand Down
12 changes: 12 additions & 0 deletions test/expected/pg_tle_management.out
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,18 @@ SELECT pgtle.available_extension_versions();
------------------------------
(0 rows)

-- Skip TransactionStmts
BEGIN;
SELECT pgtle.available_extension_versions();
available_extension_versions
------------------------------
(0 rows)

SELECT 1/0;
ERROR: division by zero
SELECT pgtle.available_extension_versions();
ERROR: current transaction is aborted, commands ignored until end of transaction block
ROLLBACK;
-- clean up
RESET SESSION AUTHORIZATION;
DROP FUNCTION superuser_only();
Expand Down
7 changes: 7 additions & 0 deletions test/sql/pg_tle_management.sql
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,13 @@ SELECT pgtle.uninstall_extension('test42');

SELECT pgtle.available_extension_versions();

-- Skip TransactionStmts
BEGIN;
SELECT pgtle.available_extension_versions();
SELECT 1/0;
SELECT pgtle.available_extension_versions();
ROLLBACK;

-- clean up
RESET SESSION AUTHORIZATION;
DROP FUNCTION superuser_only();
Expand Down