forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit45f9d08
committed
Fix race condition with unprotected use of a latch pointer variable.
Commit597a87c introduced a latch pointer variable to replace useof a long-lived shared latch in the shared WalRcvData structure.This was not well thought out, because there are now hazards of thepointer variable changing while it's being inspected by anotherprocess. This could obviously lead to a core dump in code likeif (WalRcv->latch)SetLatch(WalRcv->latch);and there's a more remote risk of a torn read, if we have anyplatforms where reading/writing a pointer is not atomic.An actual problem would occur only if the walreceiver processexits (gracefully) while the startup process is trying tosignal it, but that seems well within the realm of possibility.To fix, treat the pointer variable (not the referenced latch)as being protected by the WalRcv->mutex spinlock. Thereremains a race condition that we could apply SetLatch to aprocess latch that no longer belongs to the walreceiver, butI believe that's harmless: at worst it'd cause an extra wakeupof the next process to use that PGPROC structure.Back-patch to v10 where the faulty code was added.Discussion:https://postgr.es/m/22735.1507048202@sss.pgh.pa.us1 parent89e434b commit45f9d08
File tree
3 files changed
+27
-16
lines changed- src
- backend/replication
- include/replication
3 files changed
+27
-16
lines changedLines changed: 13 additions & 6 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
256 | 256 |
| |
257 | 257 |
| |
258 | 258 |
| |
| 259 | + | |
| 260 | + | |
| 261 | + | |
259 | 262 |
| |
260 | 263 |
| |
261 | 264 |
| |
262 | 265 |
| |
263 | 266 |
| |
264 |
| - | |
265 |
| - | |
266 | 267 |
| |
267 | 268 |
| |
268 | 269 |
| |
| |||
777 | 778 |
| |
778 | 779 |
| |
779 | 780 |
| |
780 |
| - | |
781 |
| - | |
| 781 | + | |
782 | 782 |
| |
783 | 783 |
| |
784 | 784 |
| |
| |||
789 | 789 |
| |
790 | 790 |
| |
791 | 791 |
| |
| 792 | + | |
792 | 793 |
| |
793 | 794 |
| |
794 | 795 |
| |
| |||
1344 | 1345 |
| |
1345 | 1346 |
| |
1346 | 1347 |
| |
| 1348 | + | |
| 1349 | + | |
1347 | 1350 |
| |
1348 |
| - | |
1349 |
| - | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
1350 | 1357 |
| |
1351 | 1358 |
| |
1352 | 1359 |
| |
|
Lines changed: 5 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
226 | 226 |
| |
227 | 227 |
| |
228 | 228 |
| |
| 229 | + | |
229 | 230 |
| |
230 | 231 |
| |
231 | 232 |
| |
| |||
274 | 275 |
| |
275 | 276 |
| |
276 | 277 |
| |
| 278 | + | |
| 279 | + | |
277 | 280 |
| |
278 | 281 |
| |
279 | 282 |
| |
280 | 283 |
| |
281 |
| - | |
282 |
| - | |
| 284 | + | |
| 285 | + | |
283 | 286 |
| |
284 | 287 |
| |
285 | 288 |
| |
|
Lines changed: 9 additions & 8 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
117 | 117 |
| |
118 | 118 |
| |
119 | 119 |
| |
120 |
| - | |
121 |
| - | |
122 |
| - | |
123 |
| - | |
124 |
| - | |
125 |
| - | |
126 |
| - | |
127 |
| - | |
128 | 120 |
| |
129 | 121 |
| |
130 | 122 |
| |
| |||
133 | 125 |
| |
134 | 126 |
| |
135 | 127 |
| |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
136 | 137 |
| |
137 | 138 |
| |
138 | 139 |
| |
|
0 commit comments
Comments
(0)