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

Commit41bd2cf

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 parent0d11fed commit41bd2cf

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
@@ -404,12 +404,25 @@ errfinish(int dummy,...)
404404
{
405405
ErrorData*edata=&errordata[errordata_stack_depth];
406406
intelevel=edata->elevel;
407+
boolsave_ImmediateInterruptOK;
407408
MemoryContextoldcontext;
408409
ErrorContextCallback*econtext;
409410

410411
recursion_depth++;
411412
CHECK_STACK_DEPTH();
412413

414+
/*
415+
* Ensure we can't get interrupted while performing error reporting. This
416+
* is needed to prevent recursive entry to functions like syslog(), which
417+
* may not be re-entrant.
418+
*
419+
* Note: other places that save-and-clear ImmediateInterruptOK also do
420+
* HOLD_INTERRUPTS(), but that should not be necessary here since we
421+
* don't call anything that could turn on ImmediateInterruptOK.
422+
*/
423+
save_ImmediateInterruptOK=ImmediateInterruptOK;
424+
ImmediateInterruptOK= false;
425+
413426
/*
414427
* Do processing in ErrorContext, which we hope has enough reserved space
415428
* to report an error.
@@ -435,17 +448,16 @@ errfinish(int dummy,...)
435448
/*
436449
* We do some minimal cleanup before longjmp'ing so that handlers can
437450
* execute in a reasonably sane state.
438-
*/
439-
440-
/* This is just in case the error came while waiting for input */
441-
ImmediateInterruptOK= false;
442-
443-
/*
451+
*
444452
* Reset InterruptHoldoffCount in case we ereport'd from inside an
445453
* interrupt holdoff section. (We assume here that no handler will
446454
* itself be inside a holdoff section.If necessary, such a handler
447455
* could save and restore InterruptHoldoffCount for itself, but this
448456
* should make life easier for most.)
457+
*
458+
* Note that we intentionally don't restore ImmediateInterruptOK here,
459+
* even if it was set at entry. We definitely don't want that on
460+
* while doing error cleanup.
449461
*/
450462
InterruptHoldoffCount=0;
451463

@@ -512,10 +524,7 @@ errfinish(int dummy,...)
512524
{
513525
/*
514526
* For a FATAL error, we let proc_exit clean up and exit.
515-
*/
516-
ImmediateInterruptOK= false;
517-
518-
/*
527+
*
519528
* If we just reported a startup failure, the client will disconnect
520529
* on receiving it, so don't send any more to the client.
521530
*/
@@ -548,15 +557,18 @@ errfinish(int dummy,...)
548557
* XXX: what if we are *in* the postmaster? abort() won't kill our
549558
* children...
550559
*/
551-
ImmediateInterruptOK= false;
552560
fflush(stdout);
553561
fflush(stderr);
554562
abort();
555563
}
556564

557565
/*
558-
* We reach here if elevel <= WARNING. OK to return to caller.
559-
*
566+
* We reach here if elevel <= WARNING. OK to return to caller, so restore
567+
* caller's setting of ImmediateInterruptOK.
568+
*/
569+
ImmediateInterruptOK=save_ImmediateInterruptOK;
570+
571+
/*
560572
* But check for cancel/die interrupt first --- this is so that the user
561573
* can stop a query emitting tons of notice or warning messages, even if
562574
* it's in a loop that otherwise fails to check for interrupts.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp