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

Commite14ed8e

Browse files
committed
Block signals while computing the sleep time in postmaster's main loop.
DetermineSleepTime() was previously called without blockedsignals. That's not good, because it allows signal handlers tointerrupt its workings.DetermineSleepTime() was added in 9.3 with the addition of backgroundworkers (da07a1e), where it only read fromBackgroundWorkerList.Since 9.4, where dynamic background workers were added (7f7485a),the list is also manipulated in DetermineSleepTime(). That's badbecause the list now can be persistently corrupted if modified by botha signal handler and DetermineSleepTime().This was discovered during the investigation of hangs on buildfarmmember anole. It's unclear whether this bug is the source of thesehangs or not, but it's worth fixing either way. I have confirmed thatit can cause crashes.It luckily looks like this only can cause problems when bgworkers areactively used.Discussion: 20140929193733.GB14400@awork2.anarazel.deBackpatch to 9.3 where background workers were introduced.
1 parentce84b06 commite14ed8e

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

‎src/backend/postmaster/postmaster.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,6 +1486,8 @@ DetermineSleepTime(struct timeval * timeout)
14861486

14871487
/*
14881488
* Main idle loop of postmaster
1489+
*
1490+
* NB: Needs to be called with signals blocked
14891491
*/
14901492
staticint
14911493
ServerLoop(void)
@@ -1507,34 +1509,38 @@ ServerLoop(void)
15071509
/*
15081510
* Wait for a connection request to arrive.
15091511
*
1512+
* We block all signals except while sleeping. That makes it safe for
1513+
* signal handlers, which again block all signals while executing, to
1514+
* do nontrivial work.
1515+
*
15101516
* If we are in PM_WAIT_DEAD_END state, then we don't want to accept
1511-
* any new connections, so we don't call select() at all; just sleep
1512-
* for a little bit with signals unblocked.
1517+
* any new connections, so we don't call select(), and just sleep.
15131518
*/
15141519
memcpy((char*)&rmask, (char*)&readmask,sizeof(fd_set));
15151520

1516-
PG_SETMASK(&UnBlockSig);
1517-
15181521
if (pmState==PM_WAIT_DEAD_END)
15191522
{
1523+
PG_SETMASK(&UnBlockSig);
1524+
15201525
pg_usleep(100000L);/* 100 msec seems reasonable */
15211526
selres=0;
1527+
1528+
PG_SETMASK(&BlockSig);
15221529
}
15231530
else
15241531
{
15251532
/* must set timeout each time; some OSes change it! */
15261533
structtimevaltimeout;
15271534

1535+
/* Needs to run with blocked signals! */
15281536
DetermineSleepTime(&timeout);
15291537

1538+
PG_SETMASK(&UnBlockSig);
1539+
15301540
selres=select(nSockets,&rmask,NULL,NULL,&timeout);
1531-
}
15321541

1533-
/*
1534-
* Block all signals until we wait again. (This makes it safe for our
1535-
* signal handlers to do nontrivial work.)
1536-
*/
1537-
PG_SETMASK(&BlockSig);
1542+
PG_SETMASK(&BlockSig);
1543+
}
15381544

15391545
/* Now check the select() result */
15401546
if (selres<0)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp