From bebb95abe7a55173cab0558da3373d6a3631465b Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Wed, 16 Dec 2009 17:19:14 +0200 Subject: [PATCH 3/3] Time out the ereport() call in quickdie() after 60 seconds --- src/backend/tcop/postgres.c | 25 +++++++++++++++++++++++++ 1 files changed, 25 insertions(+), 0 deletions(-) diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c index b2fb501..ab6805a 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -191,6 +191,7 @@ static bool IsTransactionExitStmtList(List *parseTrees); static bool IsTransactionStmtList(List *parseTrees); static void drop_unnamed_stmt(void); static void SigHupHandler(SIGNAL_ARGS); +static void quickdie_alarm_handler(SIGNAL_ARGS); static void log_disconnections(int code, Datum arg); @@ -2539,9 +2540,17 @@ void quickdie(SIGNAL_ARGS) { sigaddset(&BlockSig, SIGQUIT); /* prevent nested calls */ + sigdelset(&BlockSig, SIGALRM); PG_SETMASK(&BlockSig); /* + * Set up a timeout in case the ereport() call below blocks for a + * long time. + */ + pqsignal(SIGALRM, quickdie_alarm_handler); + alarm(60); + + /* * If we're aborting out of client auth, don't risk trying to send * anything to the client; we will likely violate the protocol, * not to mention that we may have interrupted the guts of OpenSSL @@ -2586,6 +2595,22 @@ quickdie(SIGNAL_ARGS) } /* + * Take over quickdie()'s work if the alarm expired. + */ +static void +quickdie_alarm_handler(SIGNAL_ARGS) +{ + /* + * We got here if ereport() was blocking, so don't go there again + * except when really asked for. + */ + elog(DEBUG5, "quickdie aborted by alarm"); + + on_exit_reset(); + exit(2); +} + +/* * Shutdown signal from postmaster: abort transaction and exit * at soonest convenient time */ -- 1.6.5