I've been doing an excess of immediate shutdowns lately, and that has turned
up bugs old and new. This one goes back to 8.4 or earlier. If a query cancel
is pending when a backend receives SIGQUIT, the cancel takes precedence and
the backend survives:
[local] test=# select nmtest_spin(false);
Cancel request sent
WARNING: terminating connection because of crash of another server process
DETAIL: The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.
HINT: In a moment you should be able to reconnect to the database and repeat your command.
ERROR: canceling statement due to user request
Time: 4932.257 ms
[local] test=# select 1;
The errfinish() pertaining to that WARNING issues CHECK_FOR_INTERRUPTS(), and
the query cancel pending since before the SIGQUIT arrived then takes effect.
This is less bad on 9.4, because the postmaster will SIGKILL the backend after
5s. On older releases, the backend persists indefinitely.
Let's fix this by holding interrupts for the duration of quickdie(); see
attached patch. Surely we don't want any other kind of backend demise taking
precedence over quickdie(). Unfortunately, this patch does not fully prevent
that. If ImmediateInterruptOK==true, a SIGINT could arrive and longjmp()
between the start of quickdie() and its PG_SETMASK() call. The only
decently-portable way I know to close that race is to name SIGINT/SIGTERM in
the SIGQUIT handler's sa_mask. In any event, that's a *far* narrower race and
is a general problem shared by most of our signal use. I'm content to not fix
it in this patch, but I propose adding it as a TODO.
Here is the source code for the nmtest_spin() function used above:
bool no_sigquit = PG_GETARG_BOOL(0);
sigprocmask(SIG_BLOCK, &mask, NULL);
pgsql-hackers by date
|Next:||From: Bruce Momjian||Date: 2013-09-11 01:34:09|
|Subject: Re: Broken link in contrib/fuzzystrmatch/dmetaphone.c|
|Previous:||From: Bruce Momjian||Date: 2013-09-11 00:18:59|
|Subject: Re: One-line comment to improve understanding of