Skip to content

Commit 16dc9ba

Browse files
committed
AbortOutOfAnyTransaction() just before backend exit, to ensure that
resources are cleaned up if the user disconnected mid-transaction. Great thanks to Hiroshi for pointing out what should have been obvious...
1 parent 7bc654b commit 16dc9ba

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

src/backend/tcop/postgres.c

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.173 2000/08/29 09:36:47 petere Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.174 2000/08/30 20:30:06 tgl Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -1404,14 +1404,14 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
14041404
if (!IsUnderPostmaster)
14051405
{
14061406
puts("\nPOSTGRES backend interactive interface ");
1407-
puts("$Revision: 1.173 $ $Date: 2000/08/29 09:36:47 $\n");
1407+
puts("$Revision: 1.174 $ $Date: 2000/08/30 20:30:06 $\n");
14081408
}
14091409

14101410
/*
14111411
* Initialize the deferred trigger manager
14121412
*/
14131413
if (DeferredTriggerInit() != 0)
1414-
proc_exit(0);
1414+
goto normalexit;
14151415

14161416
SetProcessingMode(NormalProcessing);
14171417

@@ -1451,10 +1451,8 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
14511451
AbortCurrentTransaction();
14521452

14531453
if (ExitAfterAbort)
1454-
{
1455-
ProcReleaseLocks(); /* Just to be sure... */
1456-
proc_exit(0);
1457-
}
1454+
goto errorexit;
1455+
14581456
/*
14591457
* If we recovered successfully, return to normal top-level context
14601458
* and clear ErrorContext for next time.
@@ -1547,8 +1545,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
15471545
if (HandleFunctionRequest() == EOF)
15481546
{
15491547
/* lost frontend connection during F message input */
1550-
pq_close();
1551-
proc_exit(0);
1548+
goto normalexit;
15521549
}
15531550
break;
15541551

@@ -1607,11 +1604,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
16071604
*/
16081605
case 'X':
16091606
case EOF:
1610-
if (!IsUnderPostmaster)
1611-
ShutdownXLOG();
1612-
pq_close();
1613-
proc_exit(0);
1614-
break;
1607+
goto normalexit;
16151608

16161609
default:
16171610
elog(ERROR, "unknown frontend message was received");
@@ -1649,10 +1642,20 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
16491642
*/
16501643
MemoryContextCheck(TopMemoryContext);
16511644
#endif
1652-
} /* infinite for-loop */
1645+
} /* end of main loop */
1646+
1647+
normalexit:
1648+
ExitAfterAbort = true; /* ensure we will exit if elog during abort */
1649+
AbortOutOfAnyTransaction();
1650+
if (!IsUnderPostmaster)
1651+
ShutdownXLOG();
1652+
1653+
errorexit:
1654+
pq_close();
1655+
ProcReleaseLocks(); /* Just to be sure... */
1656+
proc_exit(0);
16531657

1654-
proc_exit(0); /* shouldn't get here... */
1655-
return 1;
1658+
return 1; /* keep compiler quiet */
16561659
}
16571660

16581661
#ifndef HAVE_GETRUSAGE

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