Skip to content
Snippets Groups Projects
Commit ad9a2747 authored by Peter Eisentraut's avatar Peter Eisentraut
Browse files

Fix crash when canceling parallel query


elog(FATAL) would end up calling PortalCleanup(), which would call
executor shutdown code, which could fail and crash, especially under
parallel query.  This was introduced by
8561e484, which did not want to mark an
active portal as failed by a normal transaction abort anymore.  But we
do need to do that for an elog(FATAL) exit.  Introduce a variable
shmem_exit_inprogress similar to the existing proc_exit_inprogress, so
we can tell whether we are in the FATAL exit scenario.

Reported-by: default avatarAndres Freund <andres@anarazel.de>
parent 49bff412
No related branches found
No related tags found
No related merge requests found
......@@ -39,6 +39,11 @@
*/
bool proc_exit_inprogress = false;
/*
* Set when shmem_exit() is in progress.
*/
bool shmem_exit_inprogress = false;
/*
* This flag tracks whether we've called atexit() in the current process
* (or in the parent postmaster).
......@@ -214,6 +219,8 @@ proc_exit_prepare(int code)
void
shmem_exit(int code)
{
shmem_exit_inprogress = true;
/*
* Call before_shmem_exit callbacks.
*
......
......@@ -22,6 +22,7 @@
#include "catalog/pg_type.h"
#include "commands/portalcmds.h"
#include "miscadmin.h"
#include "storage/ipc.h"
#include "utils/builtins.h"
#include "utils/memutils.h"
#include "utils/snapmgr.h"
......@@ -757,6 +758,13 @@ AtAbort_Portals(void)
{
Portal portal = hentry->portal;
/*
* When elog(FATAL) is progress, we need to set the active portal to
* failed, so that PortalCleanup() doesn't run the executor shutdown.
*/
if (portal->status == PORTAL_ACTIVE && shmem_exit_inprogress)
MarkPortalFailed(portal);
/*
* Do nothing else to cursors held over from a previous transaction.
*/
......
......@@ -63,6 +63,7 @@ typedef void (*shmem_startup_hook_type) (void);
/* ipc.c */
extern PGDLLIMPORT bool proc_exit_inprogress;
extern PGDLLIMPORT bool shmem_exit_inprogress;
extern void proc_exit(int code) pg_attribute_noreturn();
extern void shmem_exit(int code);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment