forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commita6029b1
Clarify the checks in RegisterBackgroundWorker.
In EXEC_BACKEND or single-user mode, we processshared_preload_libraries at postmaster startup as usual, but also atbackend startup. When a library calls RegisterBackgroundWorker() whenbeing loaded into a backend process, we go through the motions to addthe worker to BackgroundWorkerList, even though that is apostmaster-private data structure. Make it return early when called ina backend process, without changing BackgroundWorkerList.You could argue that it was intentional: In non-EXEC_BACKEND mode, thebackend processes inherit BackgroundWorkerList at fork(), so it doesmake some sense to initialize it to the same state in EXEC_BACKENDmode, too. It's clearly a postmaster-private structure, though, andall the functions that use it are clearly marked as "should only becalled in postmaster".You could also argue that libraries should not callRegisterBackgroundWorker() during backend startup. It's too late tocorrectly register any static background workers at that stage. Butit's a common pattern in extensions, and it doesn't seem worth thechurn to require all extensions to change it.Another sloppiness was the exception for "internal" backgroundworkers. We checked that RegisterBackgroundWorker() was called duringshared_preload_libraries processing, or the background worker was aninternal one. That exception was made in commit665d1fa to allowpostmaster to register the logical apply launcher inApplyLauncherRegister(). The way the check was written, it would notcomplain if you registered an internal background worker in a regularbackend process. But it would complain if postmaster registered abackground worker defined in a shared library, outsideshared_preload_libraries processing. I think the correct rule is thatyou can only register static background workers in the postmasterprocess, and only before the bgworker shared memory array has beeninitialized. Check for that more directly.Reviewed-by: Thomas MunroDiscussion:https://www.postgresql.org/message-id/4f95c1fc-ad3c-7974-3a8c-6faa3931804c@iki.fi1 parent6335822 commita6029b1
1 file changed
+33
-11
lines changedLines changed: 33 additions & 11 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
880 | 880 |
| |
881 | 881 |
| |
882 | 882 |
| |
883 |
| - | |
884 |
| - | |
885 |
| - | |
886 |
| - | |
887 |
| - | |
888 |
| - | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
889 | 888 |
| |
890 |
| - | |
891 |
| - | |
892 |
| - | |
893 |
| - | |
894 |
| - | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
895 | 906 |
| |
896 | 907 |
| |
897 | 908 |
| |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
898 | 920 |
| |
899 | 921 |
| |
900 | 922 |
| |
|
0 commit comments
Comments
(0)