Skip to content

Commit

Permalink
Fix error handling for already created functions that could give synt…
Browse files Browse the repository at this point in the history
…ax error in newer releases (#3249)

Our code assumes that function once created will never give syntax error. But certain fixes like 5251e4a where we disallow declaring reserved @@var, functions could have been created in earlier releases which will give syntax error while executing on a version with this commit. While throwing this syntax error at time of execution of function we have not cleaned up the contexts and aborted well which leads to a crash while executing a subsequent query.
To fix this we call terminate_batch for compile errors when we get parser syntax error.

In this PR We were crashing due to this in this action and by adding this commit we are not crashing anymore.

Issues Resolved
BABEL-5455

Signed-off-by: Kushaal Shroff <[email protected]>
  • Loading branch information
KushaalShroff authored Dec 13, 2024
1 parent a324237 commit 98f518e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion contrib/babelfishpg_tsql/src/pl_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -5349,7 +5349,7 @@ Datum
pltsql_call_handler(PG_FUNCTION_ARGS)
{
bool nonatomic;
PLtsql_function *func;
PLtsql_function *func = NULL;
PLtsql_execstate *save_cur_estate;
Datum retval;
int rc;
Expand Down Expand Up @@ -5470,6 +5470,11 @@ pltsql_call_handler(PG_FUNCTION_ARGS)
PG_FINALLY();
{
sql_dialect = saved_dialect;

/* If func is NULL then we have encountered a parser error. */
if (!func)
terminate_batch(true /* send_error */ , true /* compile_error */ , current_spi_stack_depth);

}
PG_END_TRY();

Expand Down

0 comments on commit 98f518e

Please sign in to comment.