forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commite2c8100
committed
Fix race condition in predicate-lock init code in EXEC_BACKEND builds.
Trading a little too heavily on letting the code path be the same whetherwe were creating shared data structures or only attaching to them,InitPredicateLocks() inserted the "scratch" PredicateLockTargetHash entryunconditionally. This is just wrong if we're in a postmaster child,which would only reach this code in EXEC_BACKEND builds. Most of thetime, the hash_search(HASH_ENTER) call would simply report that theentry already existed, causing no visible effect since the code did notbother to check for that possibility. However, if this happened whilesome other backend had transiently removed the "scratch" entry, thenthat other backend's eventual RestoreScratchTarget would suffer anassert failure; this appears to be the explanation for a recent failureon buildfarm member culicidae. In non-assert builds, there would beno visible consequences there either. But nonetheless this is a prettybad bug for EXEC_BACKEND builds, for two reasons:1. Each new backend would perform the hash_search(HASH_ENTER) callwithout holding any lock that would prevent concurrent access to thePredicateLockTargetHash hash table. This creates a low but certainlynonzero risk of corruption of that hash table.2. In the event that the race condition occurred, by reinserting thescratch entry too soon, we were defeating the entire purpose of thescratch entry, namely to guarantee that transaction commit could movehash table entries around with no risk of out-of-memory failure.The odds of an actual OOM failure are quite low, but not zero, and ifit did happen it would again result in corruption of the hash table.The user-visible symptoms of such corruption are a little hard to predict,but would presumably amount to misbehavior of SERIALIZABLE transactionsthat'd require a crash or postmaster restart to fix.To fix, just skip the hash insertion if IsUnderPostmaster. I alsoinserted a bunch of assertions that the expected things happendepending on whether IsUnderPostmaster is true. That might be overkill,since most comparable code in other functions isn't quite that paranoid,but once burnt twice shy.In passing, also move a couple of lines to places where they seemedto make more sense.Diagnosis of problem by Thomas Munro, patch by me. Back-patch toall supported branches.Discussion:https://postgr.es/m/10593.1500670709@sss.pgh.pa.us1 parent7086be6 commite2c8100
1 file changed
+21
-8
lines changedLines changed: 21 additions & 8 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
815 | 815 |
| |
816 | 816 |
| |
817 | 817 |
| |
| 818 | + | |
818 | 819 |
| |
819 | 820 |
| |
820 | 821 |
| |
| |||
1109 | 1110 |
| |
1110 | 1111 |
| |
1111 | 1112 |
| |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
1112 | 1117 |
| |
1113 | 1118 |
| |
1114 | 1119 |
| |
| |||
1131 | 1136 |
| |
1132 | 1137 |
| |
1133 | 1138 |
| |
1134 |
| - | |
1135 |
| - | |
1136 |
| - | |
1137 | 1139 |
| |
1138 | 1140 |
| |
1139 | 1141 |
| |
1140 | 1142 |
| |
1141 | 1143 |
| |
1142 | 1144 |
| |
1143 |
| - | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
1144 | 1155 |
| |
1145 | 1156 |
| |
1146 | 1157 |
| |
| |||
1152 | 1163 |
| |
1153 | 1164 |
| |
1154 | 1165 |
| |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
1155 | 1169 |
| |
1156 | 1170 |
| |
1157 | 1171 |
| |
| |||
1178 | 1192 |
| |
1179 | 1193 |
| |
1180 | 1194 |
| |
| 1195 | + | |
1181 | 1196 |
| |
1182 | 1197 |
| |
1183 | 1198 |
| |
| |||
1250 | 1265 |
| |
1251 | 1266 |
| |
1252 | 1267 |
| |
| 1268 | + | |
1253 | 1269 |
| |
1254 | 1270 |
| |
1255 | 1271 |
| |
| |||
1275 | 1291 |
| |
1276 | 1292 |
| |
1277 | 1293 |
| |
| 1294 | + | |
1278 | 1295 |
| |
1279 | 1296 |
| |
1280 | 1297 |
| |
| |||
1283 | 1300 |
| |
1284 | 1301 |
| |
1285 | 1302 |
| |
1286 |
| - | |
1287 |
| - | |
1288 |
| - | |
1289 |
| - | |
1290 | 1303 |
| |
1291 | 1304 |
| |
1292 | 1305 |
| |
|
0 commit comments
Comments
(0)