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

Commit57868d9

Browse files
committed
Avoid crash when rolling back within a prepared statement.
If a portal is used to run a prepared CALL or DO statement thatcontains a ROLLBACK, PortalRunMulti fails because the portal'sstatement list gets cleared by the rollback. (Since the grammardoesn't allow CALL/DO in PREPARE, the only easy way to get to this isvia extended query protocol, which treats all inputs as preparedstatements.) It's difficult to avoid resetting the portal earlybecause of resource-management issues, so work around this by teachingPortalRunMulti to be wary of portal->stmts having suddenly become NIL.The crash has only been seen to occur in v13 and HEAD (as aconsequence of commit1cff1b9 having added an extra touch ofportal->stmts). But even before that, the code involved touching aList that the portal no longer has any claim on. In the test case athand, the List will still exist because of another refcount on thecached plan; but I'm far from convinced that it's impossible for thecached plan to have been dropped by the time control gets back toPortalRunMulti. Hence, backpatch to v11 where nested transactionswere added.Thomas Munro and Tom Lane, per bug #16811 from James InformDiscussion:https://postgr.es/m/16811-c1b599b2c6c2d622@postgresql.org
1 parent1d3ce02 commit57868d9

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

‎src/backend/tcop/pquery.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,19 +1312,30 @@ PortalRunMulti(Portal portal,
13121312
}
13131313
}
13141314

1315-
/*
1316-
* Increment command counter between queries, but not after the last
1317-
* one.
1318-
*/
1319-
if (lnext(portal->stmts,stmtlist_item)!=NULL)
1320-
CommandCounterIncrement();
1321-
13221315
/*
13231316
* Clear subsidiary contexts to recover temporary memory.
13241317
*/
13251318
Assert(portal->portalContext==CurrentMemoryContext);
13261319

13271320
MemoryContextDeleteChildren(portal->portalContext);
1321+
1322+
/*
1323+
* Avoid crashing if portal->stmts has been reset. This can only
1324+
* occur if a CALL or DO utility statement executed an internal
1325+
* COMMIT/ROLLBACK (cf PortalReleaseCachedPlan). The CALL or DO must
1326+
* have been the only statement in the portal, so there's nothing left
1327+
* for us to do; but we don't want to dereference a now-dangling list
1328+
* pointer.
1329+
*/
1330+
if (portal->stmts==NIL)
1331+
break;
1332+
1333+
/*
1334+
* Increment command counter between queries, but not after the last
1335+
* one.
1336+
*/
1337+
if (lnext(portal->stmts,stmtlist_item)!=NULL)
1338+
CommandCounterIncrement();
13281339
}
13291340

13301341
/* Pop the snapshot if we pushed one. */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp