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

Commit77e760d

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 parent1dd6baf commit77e760d

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
@@ -1330,19 +1330,30 @@ PortalRunMulti(Portal portal,
13301330
}
13311331
}
13321332

1333-
/*
1334-
* Increment command counter between queries, but not after the last
1335-
* one.
1336-
*/
1337-
if (lnext(stmtlist_item)!=NULL)
1338-
CommandCounterIncrement();
1339-
13401333
/*
13411334
* Clear subsidiary contexts to recover temporary memory.
13421335
*/
13431336
Assert(portal->portalContext==CurrentMemoryContext);
13441337

13451338
MemoryContextDeleteChildren(portal->portalContext);
1339+
1340+
/*
1341+
* Avoid crashing if portal->stmts has been reset. This can only
1342+
* occur if a CALL or DO utility statement executed an internal
1343+
* COMMIT/ROLLBACK (cf PortalReleaseCachedPlan). The CALL or DO must
1344+
* have been the only statement in the portal, so there's nothing left
1345+
* for us to do; but we don't want to dereference a now-dangling list
1346+
* pointer.
1347+
*/
1348+
if (portal->stmts==NIL)
1349+
break;
1350+
1351+
/*
1352+
* Increment command counter between queries, but not after the last
1353+
* one.
1354+
*/
1355+
if (lnext(stmtlist_item)!=NULL)
1356+
CommandCounterIncrement();
13461357
}
13471358

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp