- Notifications
You must be signed in to change notification settings - Fork28
Commit81069a9
committed
Use pselect(2) not select(2), if available, to wait in postmaster's loop.
Traditionally we've unblocked signals, called select(2), and then blockedsignals again. The code expects that the select() will be cancelled withEINTR if an interrupt occurs; but there's a race condition, which is thatan already-pending signal will be delivered as soon as we unblock, and thenwhen we reach select() there will be nothing preventing it from waiting.This can result in a long delay before we perform any action thatServerLoop was supposed to have taken in response to the signal. As withthe somewhat-similar symptoms fixed by commit8939020, the main practicalproblem is slow launching of parallel workers. The window for trouble isusually pretty short, corresponding to one iteration of ServerLoop; butit's not negligible.To fix, use pselect(2) in place of select(2) where available, as that'sdesigned to solve exactly this problem. Where not available, we continueto use the old way, and are no worse off than before.pselect(2) has been required by POSIX since about 2001, so most modernplatforms should have it. A bigger portability issue is that someimplementations are said to be non-atomic, ie pselect() isn't reallyany different from unblock/select/reblock. Still, we're no worse offthan before on such a platform.There is talk of rewriting the postmaster to use a WaitEventSet andnot do signal response work in signal handlers, at which point thiscould be reverted, since we'd be using a self-pipe to solve the racecondition. But that's not happening before v11 at the earliest.Back-patch to 9.6. The problem exists much further back, but theworst symptom arises only in connection with parallel query, so itdoes not seem worth taking any portability risks in older branches.Discussion:https://postgr.es/m/9205.1492833041@sss.pgh.pa.us1 parent8939020 commit81069a9
File tree
5 files changed
+54
-19
lines changed- src
- backend/postmaster
- include
5 files changed
+54
-19
lines changedLines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
12892 | 12892 |
| |
12893 | 12893 |
| |
12894 | 12894 |
| |
12895 |
| - | |
| 12895 | + | |
12896 | 12896 |
| |
12897 | 12897 |
| |
12898 | 12898 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1429 | 1429 |
| |
1430 | 1430 |
| |
1431 | 1431 |
| |
1432 |
| - | |
| 1432 | + | |
1433 | 1433 |
| |
1434 | 1434 |
| |
1435 | 1435 |
| |
|
Lines changed: 46 additions & 17 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
614 | 614 |
| |
615 | 615 |
| |
616 | 616 |
| |
617 |
| - | |
| 617 | + | |
618 | 618 |
| |
619 |
| - | |
| 619 | + | |
620 | 620 |
| |
621 | 621 |
| |
622 | 622 |
| |
| |||
1670 | 1670 |
| |
1671 | 1671 |
| |
1672 | 1672 |
| |
| 1673 | + | |
| 1674 | + | |
1673 | 1675 |
| |
1674 | 1676 |
| |
1675 | 1677 |
| |
| |||
1679 | 1681 |
| |
1680 | 1682 |
| |
1681 | 1683 |
| |
1682 |
| - | |
1683 |
| - | |
1684 |
| - | |
1685 | 1684 |
| |
1686 |
| - | |
1687 |
| - | |
1688 | 1685 |
| |
1689 | 1686 |
| |
1690 |
| - | |
1691 |
| - | |
1692 |
| - | |
1693 |
| - | |
1694 |
| - | |
1695 |
| - | |
| 1687 | + | |
| 1688 | + | |
| 1689 | + | |
| 1690 | + | |
| 1691 | + | |
| 1692 | + | |
| 1693 | + | |
1696 | 1694 |
| |
1697 | 1695 |
| |
1698 | 1696 |
| |
1699 |
| - | |
1700 |
| - | |
| 1697 | + | |
| 1698 | + | |
| 1699 | + | |
1701 | 1700 |
| |
1702 | 1701 |
| |
1703 | 1702 |
| |
| 1703 | + | |
1704 | 1704 |
| |
| 1705 | + | |
| 1706 | + | |
| 1707 | + | |
| 1708 | + | |
| 1709 | + | |
| 1710 | + | |
| 1711 | + | |
| 1712 | + | |
| 1713 | + | |
| 1714 | + | |
| 1715 | + | |
| 1716 | + | |
| 1717 | + | |
| 1718 | + | |
| 1719 | + | |
| 1720 | + | |
| 1721 | + | |
| 1722 | + | |
| 1723 | + | |
| 1724 | + | |
| 1725 | + | |
| 1726 | + | |
| 1727 | + | |
| 1728 | + | |
| 1729 | + | |
| 1730 | + | |
| 1731 | + | |
| 1732 | + | |
1705 | 1733 |
| |
1706 | 1734 |
| |
1707 |
| - | |
| 1735 | + | |
1708 | 1736 |
| |
1709 | 1737 |
| |
| 1738 | + | |
1710 | 1739 |
| |
1711 | 1740 |
| |
1712 |
| - | |
| 1741 | + | |
1713 | 1742 |
| |
1714 | 1743 |
| |
1715 | 1744 |
| |
|
Lines changed: 3 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
400 | 400 |
| |
401 | 401 |
| |
402 | 402 |
| |
| 403 | + | |
| 404 | + | |
| 405 | + | |
403 | 406 |
| |
404 | 407 |
| |
405 | 408 |
| |
|
Lines changed: 3 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
267 | 267 |
| |
268 | 268 |
| |
269 | 269 |
| |
| 270 | + | |
| 271 | + | |
| 272 | + | |
270 | 273 |
| |
271 | 274 |
| |
272 | 275 |
| |
|
0 commit comments
Comments
(0)