forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitac23b71
committed
Fix incorrect order of database-locking operations in InitPostgres().
We should set MyProc->databaseId after acquiring the per-database lock,not beforehand. The old way risked deadlock against processes trying tocopy or delete the target database, since they would first acquire the lockand then wait for processes with matching databaseId to exit; that left awindow wherein an incoming process could set its databaseId and then blockon the lock, while the other process had the lock and waited in vain forthe incoming process to exit.CountOtherDBBackends() would time out and fail after 5 seconds, so thisjust resulted in an unexpected failure not a permanent lockup, but it'sstill annoying when it happens. A real-world example of a use-case is thatshort-duration connections to a template database should not cause CREATEDATABASE to fail.Doing it in the other order should be fine since the contract has alwaysbeen that processes searching the ProcArray for a database ID must hold therelevant per-database lock while searching. Thus, this actually removesthe former race condition that required an assumption that storing toMyProc->databaseId is atomic.It's been like this for a long time, so back-patch to all active branches.1 parent068cfad commitac23b71
1 file changed
+29
-15
lines changedLines changed: 29 additions & 15 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
848 | 848 |
| |
849 | 849 |
| |
850 | 850 |
| |
851 |
| - | |
852 |
| - | |
853 |
| - | |
854 |
| - | |
855 |
| - | |
856 |
| - | |
857 |
| - | |
858 |
| - | |
859 |
| - | |
860 |
| - | |
861 |
| - | |
862 |
| - | |
863 | 851 |
| |
864 | 852 |
| |
865 | 853 |
| |
866 | 854 |
| |
867 | 855 |
| |
868 | 856 |
| |
869 | 857 |
| |
870 |
| - | |
871 |
| - | |
872 |
| - | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
873 | 865 |
| |
874 | 866 |
| |
875 | 867 |
| |
| |||
881 | 873 |
| |
882 | 874 |
| |
883 | 875 |
| |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
884 | 898 |
| |
885 | 899 |
| |
886 | 900 |
| |
|
0 commit comments
Comments
(0)