Skip to content

Commit f2c3b7b

Browse files
committed
Fix parallel query crashes by adding NULL checks for exec_state_call_stack
In parallel workers, the exec_state_call_stack global variable is NULL because parallel workers don't have the PL/tsql execution context. When hooks like plsql_TriggerRecursiveCheck are called from parallel workers during query execution, they would crash trying to dereference the NULL pointer. This fix adds NULL checks to: - plsql_TriggerRecursiveCheck() in hooks.c - returns false if NULL - find_innermost_catch_block() in err_handler.c - returns NULL if NULL These functions are now safe to call from parallel workers and will simply return early without accessing the exec_state_call_stack.
1 parent 6ab3fe6 commit f2c3b7b

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

contrib/babelfishpg_tsql/src/err_handler.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,15 @@ do_error_mapping(PLtsql_estate_err *err)
429429
static PLtsql_execstate *
430430
find_innermost_catch_block(void)
431431
{
432-
PLExecStateCallStack *stack = exec_state_call_stack;
433-
PLtsql_execstate *estate = stack->estate;
432+
PLExecStateCallStack *stack;
433+
PLtsql_execstate *estate;
434+
435+
/* Safety check for parallel workers where exec_state_call_stack may be NULL */
436+
if (exec_state_call_stack == NULL)
437+
return NULL;
438+
439+
stack = exec_state_call_stack;
440+
estate = stack->estate;
434441

435442
while ((!estate || !estate->cur_error || !estate->cur_error->error) &&
436443
stack->next)

contrib/babelfishpg_tsql/src/hooks.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,6 +1687,9 @@ plsql_TriggerRecursiveCheck(ResultRelInfo *resultRelInfo)
16871687
return false;
16881688
if (pltsql_recursive_triggers)
16891689
return false;
1690+
/* Safety check for parallel workers where exec_state_call_stack may be NULL */
1691+
if (exec_state_call_stack == NULL)
1692+
return false;
16901693
cur = exec_state_call_stack;
16911694
while (cur != NULL)
16921695
{

0 commit comments

Comments
 (0)