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

Commit7e69421

Browse files
committed
Add HOLD/RESUME_INTERRUPTS in HandleCatchupInterrupt/HandleNotifyInterrupt.
This prevents a possible longjmp out of the signal handler if a timeoutor SIGINT occurs while something within the handler has transiently setImmediateInterruptOK. For safety we must hold off the timeout or cancelerror until we're back in mainline, or at least till we reach the end ofthe signal handler when ImmediateInterruptOK was true at entry. Thissyncs these functions with the logic now present in handle_sig_alarm.AFAICT there is no live bug here in 9.0 and up, because I don't think wecurrently can wait for any heavyweight lock inside these functions, andthere is no other code (except read-from-client) that will turn onImmediateInterruptOK. However, that was not true pre-9.0: in olderbranches ProcessIncomingNotify might block trying to lock pg_listener, andthen a SIGINT could lead to undesirable control flow. It might be allright anyway given the relatively narrow code ranges in which NOTIFYinterrupts are enabled, but for safety's sake I'm back-patching this.
1 parent1777625 commit7e69421

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

‎src/backend/commands/async.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,11 +1673,15 @@ HandleNotifyInterrupt(void)
16731673

16741674
/*
16751675
* We may be called while ImmediateInterruptOK is true; turn it off
1676-
* while messing with the NOTIFY state. (We would have to save and
1677-
* restore it anyway, because PGSemaphore operations inside
1678-
* ProcessIncomingNotify() might reset it.)
1676+
* while messing with the NOTIFY state. This prevents problems if
1677+
* SIGINT or similar arrives while we're working. Just to be real
1678+
* sure, bump the interrupt holdoff counter as well. That way, even
1679+
* if something inside ProcessIncomingNotify() transiently sets
1680+
* ImmediateInterruptOK (eg while waiting on a lock), we won't get
1681+
* interrupted until we're done with the notify interrupt.
16791682
*/
16801683
ImmediateInterruptOK= false;
1684+
HOLD_INTERRUPTS();
16811685

16821686
/*
16831687
* I'm not sure whether some flavors of Unix might allow another
@@ -1707,8 +1711,10 @@ HandleNotifyInterrupt(void)
17071711
}
17081712

17091713
/*
1710-
* Restore ImmediateInterruptOK, and check for interrupts if needed.
1714+
* Restore the holdoff level and ImmediateInterruptOK, and check for
1715+
* interrupts if needed.
17111716
*/
1717+
RESUME_INTERRUPTS();
17121718
ImmediateInterruptOK=save_ImmediateInterruptOK;
17131719
if (save_ImmediateInterruptOK)
17141720
CHECK_FOR_INTERRUPTS();

‎src/backend/storage/ipc/sinval.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,15 @@ HandleCatchupInterrupt(void)
174174

175175
/*
176176
* We may be called while ImmediateInterruptOK is true; turn it off
177-
* while messing with the catchup state. (We would have to save and
178-
* restore it anyway, because PGSemaphore operations inside
179-
* ProcessCatchupEvent() might reset it.)
177+
* while messing with the catchup state. This prevents problems if
178+
* SIGINT or similar arrives while we're working. Just to be real
179+
* sure, bump the interrupt holdoff counter as well. That way, even
180+
* if something inside ProcessCatchupEvent() transiently sets
181+
* ImmediateInterruptOK (eg while waiting on a lock), we won't get
182+
* interrupted until we're done with the catchup interrupt.
180183
*/
181184
ImmediateInterruptOK= false;
185+
HOLD_INTERRUPTS();
182186

183187
/*
184188
* I'm not sure whether some flavors of Unix might allow another
@@ -202,8 +206,10 @@ HandleCatchupInterrupt(void)
202206
}
203207

204208
/*
205-
* Restore ImmediateInterruptOK, and check for interrupts if needed.
209+
* Restore the holdoff level and ImmediateInterruptOK, and check for
210+
* interrupts if needed.
206211
*/
212+
RESUME_INTERRUPTS();
207213
ImmediateInterruptOK=save_ImmediateInterruptOK;
208214
if (save_ImmediateInterruptOK)
209215
CHECK_FOR_INTERRUPTS();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp