BUG #17416: Server crashes due to python3 stack overflow on executing multiple plpy.rollback() calls

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: exclusion(at)gmail(dot)com
Subject: BUG #17416: Server crashes due to python3 stack overflow on executing multiple plpy.rollback() calls
Date: 2022-02-23 11:00:01
Message-ID: 17416-ed8fe5d7213d6c25@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 17416
Logged by: Alexander Lakhin
Email address: exclusion(at)gmail(dot)com
PostgreSQL version: 14.2
Operating system: Ubuntu 20.04
Description:

When executing the following script:
psql -c "
CREATE EXTENSION plpython3u;

CREATE FUNCTION plpy_xact_test() RETURNS int
LANGUAGE plpython3u
AS '
plpy.rollback()
return 1
'"

for i in `seq 500`; do echo "SELECT plpy_xact_test();"; done | psql

I get the server crash with the following stack trace:
Core was generated by `postgres: law regression [local] SELECT
'.
Program terminated with signal SIGABRT, Aborted.
#0 __GI_raise (sig=sig(at)entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
50 ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
#0 __GI_raise (sig=sig(at)entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1 0x00007f27fc652859 in __GI_abort () at abort.c:79
#2 0x00007f27f2987c38 in ?? () from
/usr/lib/x86_64-linux-gnu/libpython3.8.so.1.0
#3 0x00007f27f2aa56a9 in Py_FatalError () from
/usr/lib/x86_64-linux-gnu/libpython3.8.so.1.0
#4 0x00007f27f2ade3e7 in _Py_CheckRecursiveCall () from
/usr/lib/x86_64-linux-gnu/libpython3.8.so.1.0
#5 0x00007f27f2b7237c in ?? () from
/usr/lib/x86_64-linux-gnu/libpython3.8.so.1.0
#6 0x00007f27f2bbc9b6 in _PyObject_CallMethodId () from
/usr/lib/x86_64-linux-gnu/libpython3.8.so.1.0
#7 0x00007f27f2aa5260 in ?? () from
/usr/lib/x86_64-linux-gnu/libpython3.8.so.1.0
#8 0x00007f27f2aa555b in ?? () from
/usr/lib/x86_64-linux-gnu/libpython3.8.so.1.0
#9 0x00007f27f2aa56a9 in Py_FatalError () from
/usr/lib/x86_64-linux-gnu/libpython3.8.so.1.0
#10 0x00007f27f2ade3e7 in _Py_CheckRecursiveCall () from
/usr/lib/x86_64-linux-gnu/libpython3.8.so.1.0
#11 0x00007f27f29884ec in _PyEval_EvalFrameDefault () from
/usr/lib/x86_64-linux-gnu/libpython3.8.so.1.0
#12 0x00007f27f2addecb in _PyEval_EvalCodeWithName () from
/usr/lib/x86_64-linux-gnu/libpython3.8.so.1.0
#13 0x00007f27f2ade252 in PyEval_EvalCodeEx () from
/usr/lib/x86_64-linux-gnu/libpython3.8.so.1.0
#14 0x00007f27f2ade63f in PyEval_EvalCode () from
/usr/lib/x86_64-linux-gnu/libpython3.8.so.1.0
#15 0x00007f27f2ec0078 in PLy_procedure_call (proc=0x5616bf113c80,
kargs=0x7f27f2ecb79d "args", vargs=0x7f27f2808500)
at plpy_exec.c:1032
#16 0x00007f27f2ebd4aa in PLy_exec_function (fcinfo=0x5616bf110398,
proc=0x5616bf113c80) at plpy_exec.c:104
#17 0x00007f27f2ec0a11 in plpython3_call_handler (fcinfo=0x5616bf110398) at
plpy_main.c:270
#18 0x00005616bdb70449 in ExecInterpExpr (state=0x5616bf1102b0,
econtext=0x5616bf10ffb0, isnull=0x7ffdc73aea3f)
at execExprInterp.c:725
#19 0x00005616bdb728dc in ExecInterpExprStillValid (state=0x5616bf1102b0,
econtext=0x5616bf10ffb0,
isNull=0x7ffdc73aea3f) at execExprInterp.c:1824
#20 0x00005616bdbcdfb3 in ExecEvalExprSwitchContext (state=0x5616bf1102b0,
econtext=0x5616bf10ffb0,
isNull=0x7ffdc73aea3f) at ../../../src/include/executor/executor.h:339
#21 0x00005616bdbce02b in ExecProject (projInfo=0x5616bf1102a8) at
../../../src/include/executor/executor.h:373
#22 0x00005616bdbce275 in ExecResult (pstate=0x5616bf10fe98) at
nodeResult.c:136
#23 0x00005616bdb88cb0 in ExecProcNodeFirst (node=0x5616bf10fe98) at
execProcnode.c:463
#24 0x00005616bdb7c79c in ExecProcNode (node=0x5616bf10fe98) at
../../../src/include/executor/executor.h:257
#25 0x00005616bdb7f3ba in ExecutePlan (estate=0x5616bf10fc60,
planstate=0x5616bf10fe98, use_parallel_mode=false,
operation=CMD_SELECT, sendTuples=true, numberTuples=0,
direction=ForwardScanDirection, dest=0x5616bf0191d0,
execute_once=true) at execMain.c:1551
#26 0x00005616bdb7ced3 in standard_ExecutorRun (queryDesc=0x5616bef7da10,
direction=ForwardScanDirection, count=0,
execute_once=true) at execMain.c:361
#27 0x00005616bdb7ccbe in ExecutorRun (queryDesc=0x5616bef7da10,
direction=ForwardScanDirection, count=0,
execute_once=true) at execMain.c:305
#28 0x00005616bddfa2ec in PortalRunSelect (portal=0x5616befbf3e0,
forward=true, count=0, dest=0x5616bf0191d0)
at pquery.c:921
#29 0x00005616bddf9f10 in PortalRun (portal=0x5616befbf3e0,
count=9223372036854775807, isTopLevel=true, run_once=true,
dest=0x5616bf0191d0, altdest=0x5616bf0191d0, qc=0x7ffdc73aee40) at
pquery.c:765
#30 0x00005616bddf2e22 in exec_simple_query (query_string=0x5616bef5b980
"SELECT plpy_xact_test();") at postgres.c:1214
#31 0x00005616bddf7ce9 in PostgresMain (argc=1, argv=0x7ffdc73af060,
dbname=0x5616bef872c8 "regression",
username=0x5616bef872a8 "law") at postgres.c:4496
#32 0x00005616bdd1c4d3 in BackendRun (port=0x5616bef7cf00) at
postmaster.c:4530
#33 0x00005616bdd1bd2e in BackendStartup (port=0x5616bef7cf00) at
postmaster.c:4252
#34 0x00005616bdd17b23 in ServerLoop () at postmaster.c:1745
#35 0x00005616bdd17280 in PostmasterMain (argc=3, argv=0x5616bef559b0) at
postmaster.c:1417
#36 0x00005616bdc06738 in main (argc=3, argv=0x5616bef559b0) at main.c:209

The server log contains:
..
2022-02-23 12:58:23.640 MSK [810462] ERROR: invalid transaction
termination
2022-02-23 12:58:23.640 MSK [810462] CONTEXT: PL/Python function
"plpy_xact_test"
2022-02-23 12:58:23.640 MSK [810462] STATEMENT: SELECT plpy_xact_test();
2022-02-23 12:58:23.641 MSK [810462] ERROR: invalid transaction
termination
...
2022-02-23 12:58:23.657 MSK [810462] STATEMENT: SELECT plpy_xact_test();
2022-02-23 12:58:23.657 MSK [810462] ERROR: RecursionError: maximum
recursion depth exceeded
2022-02-23 12:58:23.657 MSK [810462] CONTEXT: Traceback (most recent call
last):
PL/Python function "plpy_xact_test"
2022-02-23 12:58:23.657 MSK [810462] STATEMENT: SELECT plpy_xact_test();
2022-02-23 12:58:23.657 MSK [810462] ERROR: invalid transaction
termination
2022-02-23 12:58:23.657 MSK [810462] CONTEXT: PL/Python function
"plpy_xact_test"
2022-02-23 12:58:23.657 MSK [810462] STATEMENT: SELECT plpy_xact_test();
2022-02-23 12:58:23.657 MSK [810462] ERROR: invalid transaction
termination
2022-02-23 12:58:23.657 MSK [810462] CONTEXT: PL/Python function
"plpy_xact_test"
2022-02-23 12:58:23.657 MSK [810462] STATEMENT: SELECT plpy_xact_test();
...
2022-02-23 12:58:23.658 MSK [810462] ERROR: invalid transaction
termination
2022-02-23 12:58:23.658 MSK [810462] CONTEXT: PL/Python function
"plpy_xact_test"
2022-02-23 12:58:23.658 MSK [810462] STATEMENT: SELECT plpy_xact_test();
Fatal Python error: Cannot recover from stack overflow.
Python runtime state: initialized

Current thread 0x00007f27fc628740 (most recent call first):
File "<string>", line 3 in __plpython_procedure_plpy_xact_test_16390
File "<string>", line 1 in <module>
File "<string>", line 3 in __plpython_procedure_plpy_xact_test_16390
File "<string>", line 1 in <module>
File "<string>", line 3 in __plpython_procedure_plpy_xact_test_16390
...
File "<string>", line 1 in <module>
File "<string>", line 3 in __plpython_procedure_plpy_xact_test_16390
File "<string>", line 1 in <module>
...
2022-02-23 12:58:23.818 MSK [810446] LOG: server process (PID 810462) was
terminated by signal 6: Aborted
2022-02-23 12:58:23.818 MSK [810446] DETAIL: Failed process was running:
SELECT plpy_xact_test();

Reproduced on REL_11_0..master.

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Japin Li 2022-02-23 13:54:49 Re: BUG #17415: Unable to use underscore as first character in set_config custom parameter
Previous Message PG Bug reporting form 2022-02-23 08:36:19 BUG #17415: Unable to use underscore as first character in set_config custom parameter