Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf16ca97

Browse files
committed
Prevent interrupts while reporting non-ERROR elog messages.
This should eliminate the risk of recursive entry to syslog(3), whichappears to be the cause of the hang reported in bug #9551 from JamesMorton.Arguably, the real problem here is auth.c's willingness to turn onImmediateInterruptOK while executing fairly wide swaths of backend code.We may well need to work at narrowing the code ranges in which theauthentication_timeout interrupt is enabled. For the moment, though,this is a cheap and reasonably noninvasive fix for a field-reportedfailure; the other approach would be complex and not necessarilybug-free itself.Back-patch to all supported branches.
1 parent7bfdf10 commitf16ca97

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

‎src/backend/utils/error/elog.c

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -396,12 +396,25 @@ errfinish(int dummy,...)
396396
{
397397
ErrorData*edata=&errordata[errordata_stack_depth];
398398
intelevel=edata->elevel;
399+
boolsave_ImmediateInterruptOK;
399400
MemoryContextoldcontext;
400401
ErrorContextCallback*econtext;
401402

402403
recursion_depth++;
403404
CHECK_STACK_DEPTH();
404405

406+
/*
407+
* Ensure we can't get interrupted while performing error reporting. This
408+
* is needed to prevent recursive entry to functions like syslog(), which
409+
* may not be re-entrant.
410+
*
411+
* Note: other places that save-and-clear ImmediateInterruptOK also do
412+
* HOLD_INTERRUPTS(), but that should not be necessary here since we
413+
* don't call anything that could turn on ImmediateInterruptOK.
414+
*/
415+
save_ImmediateInterruptOK=ImmediateInterruptOK;
416+
ImmediateInterruptOK= false;
417+
405418
/*
406419
* Do processing in ErrorContext, which we hope has enough reserved space
407420
* to report an error.
@@ -427,17 +440,16 @@ errfinish(int dummy,...)
427440
/*
428441
* We do some minimal cleanup before longjmp'ing so that handlers can
429442
* execute in a reasonably sane state.
430-
*/
431-
432-
/* This is just in case the error came while waiting for input */
433-
ImmediateInterruptOK= false;
434-
435-
/*
443+
*
436444
* Reset InterruptHoldoffCount in case we ereport'd from inside an
437445
* interrupt holdoff section. (We assume here that no handler will
438446
* itself be inside a holdoff section.If necessary, such a handler
439447
* could save and restore InterruptHoldoffCount for itself, but this
440448
* should make life easier for most.)
449+
*
450+
* Note that we intentionally don't restore ImmediateInterruptOK here,
451+
* even if it was set at entry. We definitely don't want that on
452+
* while doing error cleanup.
441453
*/
442454
InterruptHoldoffCount=0;
443455

@@ -494,10 +506,7 @@ errfinish(int dummy,...)
494506
{
495507
/*
496508
* For a FATAL error, we let proc_exit clean up and exit.
497-
*/
498-
ImmediateInterruptOK= false;
499-
500-
/*
509+
*
501510
* If we just reported a startup failure, the client will disconnect
502511
* on receiving it, so don't send any more to the client.
503512
*/
@@ -530,15 +539,18 @@ errfinish(int dummy,...)
530539
* XXX: what if we are *in* the postmaster? abort() won't kill our
531540
* children...
532541
*/
533-
ImmediateInterruptOK= false;
534542
fflush(stdout);
535543
fflush(stderr);
536544
abort();
537545
}
538546

539547
/*
540-
* We reach here if elevel <= WARNING. OK to return to caller.
541-
*
548+
* We reach here if elevel <= WARNING. OK to return to caller, so restore
549+
* caller's setting of ImmediateInterruptOK.
550+
*/
551+
ImmediateInterruptOK=save_ImmediateInterruptOK;
552+
553+
/*
542554
* But check for cancel/die interrupt first --- this is so that the user
543555
* can stop a query emitting tons of notice or warning messages, even if
544556
* it's in a loop that otherwise fails to check for interrupts.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp