Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6f38c43

Browse files
committed
Avoid stack overflow in ShowTransactionStateRec()
The function recurses, but didn't perform stack-depth checks. It'sjust a debugging aid, so instead of the usual check_stack_depth()call, stop the printing if we'd risk stack overflow.Here's an example of how to test this: (n=1000000; printf "BEGIN;"; for ((i=1;i<=$n;i++)); do printf "SAVEPOINT s$i;"; done; printf "SET log_min_messages = 'DEBUG5'; SAVEPOINT sp;") | psql >/dev/nullIn the passing, swap building the list of child XIDs and recursing toparent. That saves memory while recursing, reducing the risk of out ofmemory errors with lots of subtransactions. The saving is not verysignificant in practice, but this order seems more logical anyway.Report by Egor Chindyaskin and Alexander Lakhin.Discussion:https://www.postgresql.org/message-id/1672760457.940462079%40f306.i.mail.ruAuthor: Heikki LinnakangasReviewed-by: Robert Haas, Andres Freund, Alexander Korotkov
1 parentfefd9a3 commit6f38c43

File tree

1 file changed

+15
-6
lines changed
  • src/backend/access/transam

1 file changed

+15
-6
lines changed

‎src/backend/access/transam/xact.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5583,8 +5583,22 @@ ShowTransactionStateRec(const char *str, TransactionState s)
55835583
{
55845584
StringInfoDatabuf;
55855585

5586-
initStringInfo(&buf);
5586+
if (s->parent)
5587+
{
5588+
/*
5589+
* Since this function recurses, it could be driven to stack overflow.
5590+
* This is just a debugging aid, so we can leave out some details
5591+
* instead of erroring out with check_stack_depth().
5592+
*/
5593+
if (stack_is_too_deep())
5594+
ereport(DEBUG5,
5595+
(errmsg_internal("%s(%d): parent omitted to avoid stack overflow",
5596+
str,s->nestingLevel)));
5597+
else
5598+
ShowTransactionStateRec(str,s->parent);
5599+
}
55875600

5601+
initStringInfo(&buf);
55885602
if (s->nChildXids>0)
55895603
{
55905604
inti;
@@ -5593,10 +5607,6 @@ ShowTransactionStateRec(const char *str, TransactionState s)
55935607
for (i=1;i<s->nChildXids;i++)
55945608
appendStringInfo(&buf," %u",s->childXids[i]);
55955609
}
5596-
5597-
if (s->parent)
5598-
ShowTransactionStateRec(str,s->parent);
5599-
56005610
ereport(DEBUG5,
56015611
(errmsg_internal("%s(%d) name: %s; blockState: %s; state: %s, xid/subid/cid: %u/%u/%u%s%s",
56025612
str,s->nestingLevel,
@@ -5608,7 +5618,6 @@ ShowTransactionStateRec(const char *str, TransactionState s)
56085618
(unsignedint)currentCommandId,
56095619
currentCommandIdUsed ?" (used)" :"",
56105620
buf.data)));
5611-
56125621
pfree(buf.data);
56135622
}
56145623

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp