SIGTERM -> elog(FATAL) -> proc_exit() is probably a bad idea - Mailing list pgsql-hackers

From Tom Lane
Subject SIGTERM -> elog(FATAL) -> proc_exit() is probably a bad idea
Date
Msg-id 21658.979336914@sss.pgh.pa.us
Whole thread Raw
Responses RE: SIGTERM -> elog(FATAL) -> proc_exit() is probably a bad idea  ("Hiroshi Inoue" <Inoue@tpf.co.jp>)
List pgsql-hackers
I have just finished trudging through a bunch of code and trying to make
it secure against being interrupted by die() at arbitrary instants.
However, I am under no illusion that I have succeeded in making the
world safe for SIGTERM, and you shouldn't be either.  There is just way
too much code that is potentially invoked during proc_exit; even if we
fixed every line of our code, there's C library code that's not under
our control.  For example, malloc/free are not interrupt-safe on many
platforms, last I heard.  Do you want to put START/END_CRIT_SECTION
around every memory allocation operation?  I don't.

I think we'd be lots better off to abandon the notion that we can exit
directly from the SIGTERM interrupt handler, and instead treat SIGTERM
the same way we treat QueryCancel: set a flag that is inspected at
specific places where we know we are in a good state.

Comments?
        regards, tom lane


pgsql-hackers by date:

Previous
From: ncm@zembu.com (Nathan Myers)
Date:
Subject: Re: CRCs
Next
From: Bruce Momjian
Date:
Subject: Re: CVS updates on committers list...