Skip to content

Commit

Permalink
Fix error handling path in SRFs
Browse files Browse the repository at this point in the history
It should be safe to unregister a context callback even when in an
aborted subxact, the only possible errors are memory ones.

Fixes pllua#15.
  • Loading branch information
RhodiumToad committed Nov 29, 2023
1 parent f1d3258 commit 231e567
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
7 changes: 7 additions & 0 deletions expected/spi.out
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,11 @@ fetch all from mycur2;
(6 rows)

commit;
-- check correct error handling inside coroutines (issue #15)
create function pg_temp.f1() returns setof text language pllua as $$
local r = spi.rows('syntaxerror')
return 'notreached'
$$;
select * from pg_temp.f1();
ERROR: syntax error at or near "syntaxerror" at character 1
--end
8 changes: 8 additions & 0 deletions sql/spi.sql
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,12 @@ do language pllua $$ collectgarbage() $$; -- check cursor stays open
fetch all from mycur2;
commit;

-- check correct error handling inside coroutines (issue #15)

create function pg_temp.f1() returns setof text language pllua as $$
local r = spi.rows('syntaxerror')
return 'notreached'
$$;
select * from pg_temp.f1();

--end
8 changes: 7 additions & 1 deletion src/objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,13 @@ void pllua_deactivate_thread(lua_State *L, pllua_func_activation *act, ExprConte
{
Assert(act->thread != NULL);

PLLUA_TRY();
/*
* We need to be able to do this on error paths, and the unregister call
* should only ever error on logic or memory corruption cases and can't
* reach any user-supplied code, so it should be safe to use the _ERROK
* variant.
*/
PLLUA_TRY_ERROK();
{
UnregisterExprContextCallback(econtext,
pllua_resetactivation_cb,
Expand Down

0 comments on commit 231e567

Please sign in to comment.