Skip to content

Commit 6252c4f

Browse files
committed
Run a portal's cleanup hook immediately when pushing it to DONE state.
This works around the problem noted by Yamamoto Takashi in bug #5906, that there were code paths whereby we could reach AtCleanup_Portals with a portal's cleanup hook still unexecuted. The changes I made a few days ago were intended to prevent that from happening, and I think that on balance it's still a good thing to avoid, so I don't want to remove the Assert in AtCleanup_Portals. Hence do this instead.
1 parent 32fce70 commit 6252c4f

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

src/backend/tcop/pquery.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ PortalRun(Portal portal, long count, bool isTopLevel,
814814
dest, altdest, completionTag);
815815

816816
/* Prevent portal's commands from being re-executed */
817-
portal->status = PORTAL_DONE;
817+
MarkPortalDone(portal);
818818

819819
/* Always complete at end of RunMulti */
820820
result = true;

src/backend/utils/mmgr/portalmem.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,32 @@ UnpinPortal(Portal portal)
401401
portal->portalPinned = false;
402402
}
403403

404+
/*
405+
* MarkPortalDone
406+
* Transition a portal from ACTIVE to DONE state.
407+
*/
408+
void
409+
MarkPortalDone(Portal portal)
410+
{
411+
/* Perform the state transition */
412+
Assert(portal->status == PORTAL_ACTIVE);
413+
portal->status = PORTAL_DONE;
414+
415+
/*
416+
* Allow portalcmds.c to clean up the state it knows about. We might
417+
* as well do that now, since the portal can't be executed any more.
418+
*
419+
* In some cases involving execution of a ROLLBACK command in an already
420+
* aborted transaction, this prevents an assertion failure from reaching
421+
* AtCleanup_Portals with the cleanup hook still unexecuted.
422+
*/
423+
if (PointerIsValid(portal->cleanup))
424+
{
425+
(*portal->cleanup) (portal);
426+
portal->cleanup = NULL;
427+
}
428+
}
429+
404430
/*
405431
* PortalDrop
406432
* Destroy the portal.

src/include/utils/portal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ extern Portal CreatePortal(const char *name, bool allowDup, bool dupSilent);
206206
extern Portal CreateNewPortal(void);
207207
extern void PinPortal(Portal portal);
208208
extern void UnpinPortal(Portal portal);
209+
extern void MarkPortalDone(Portal portal);
209210
extern void PortalDrop(Portal portal, bool isTopCommit);
210211
extern Portal GetPortalByName(const char *name);
211212
extern void PortalDefineQuery(Portal portal,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy