forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit1518d07
committed
Fix crash when logical decoding is invoked from a PL function.
The logical decoding functions do BeginInternalSubTransaction andRollbackAndReleaseCurrentSubTransaction to clean up after themselves.It turns out that AtEOSubXact_SPI has an unrecognized assumption thatwe always need to cancel the active SPI operation in the SPI contextthat surrounds the subtransaction (if there is one). That's truewhen the RollbackAndReleaseCurrentSubTransaction call is coming fromthe SPI-using function itself, but not when it's happening insidesome unrelated function invoked by a SPI query. In practice theaffected callers are the various PLs.To fix, record the current subtransaction ID when we begin a SPIoperation, and clean up only if that ID is the subtransaction beingcanceled.Also, remove AtEOSubXact_SPI's assertion that it must have cleanedup the surrounding SPI context's active tuptable. That's provenwrong by the same test case.Also clarify (or, if you prefer, reinterpret) the calling conventionsfor _SPI_begin_call and _SPI_end_call. The memory context cleanupin the latter means that these have always had the flavor of a matchedresource-management pair, but they weren't documented that way before.Per report from Ben Chobot.Back-patch to 9.4 where logical decoding came in. In principle,the SPI changes should go all the way back, since the problem datesback to commit7ec1c5a. But given the lack of field complaintsit seems few people are using internal subtransactions in this way.So I don't feel a need to take any risks in 9.2/9.3.Discussion:https://postgr.es/m/73FBA179-C68C-4540-9473-71E865408B15@silentmedia.com1 parent45866c7 commit1518d07
File tree
4 files changed
+70
-11
lines changed- contrib/test_decoding
- expected
- sql
- src
- backend/executor
- include/executor
4 files changed
+70
-11
lines changedLines changed: 25 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
59 | 59 |
| |
60 | 60 |
| |
61 | 61 |
| |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
62 | 87 |
| |
63 | 88 |
| |
64 | 89 |
| |
|
Lines changed: 11 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
27 | 27 |
| |
28 | 28 |
| |
29 | 29 |
| |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
30 | 40 |
| |
| 41 | + | |
31 | 42 |
|
Lines changed: 31 additions & 11 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
71 | 71 |
| |
72 | 72 |
| |
73 | 73 |
| |
74 |
| - | |
75 |
| - | |
| 74 | + | |
| 75 | + | |
76 | 76 |
| |
77 | 77 |
| |
78 | 78 |
| |
| |||
118 | 118 |
| |
119 | 119 |
| |
120 | 120 |
| |
| 121 | + | |
121 | 122 |
| |
122 | 123 |
| |
123 | 124 |
| |
| |||
149 | 150 |
| |
150 | 151 |
| |
151 | 152 |
| |
152 |
| - | |
| 153 | + | |
153 | 154 |
| |
154 | 155 |
| |
155 | 156 |
| |
| |||
268 | 269 |
| |
269 | 270 |
| |
270 | 271 |
| |
271 |
| - | |
272 |
| - | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
273 | 281 |
| |
274 | 282 |
| |
275 | 283 |
| |
| |||
293 | 301 |
| |
294 | 302 |
| |
295 | 303 |
| |
296 |
| - | |
297 |
| - | |
298 | 304 |
| |
299 | 305 |
| |
300 | 306 |
| |
| |||
2446 | 2452 |
| |
2447 | 2453 |
| |
2448 | 2454 |
| |
| 2455 | + | |
| 2456 | + | |
| 2457 | + | |
| 2458 | + | |
2449 | 2459 |
| |
2450 | 2460 |
| |
2451 |
| - | |
| 2461 | + | |
2452 | 2462 |
| |
2453 | 2463 |
| |
2454 | 2464 |
| |
2455 | 2465 |
| |
2456 |
| - | |
| 2466 | + | |
| 2467 | + | |
| 2468 | + | |
| 2469 | + | |
| 2470 | + | |
2457 | 2471 |
| |
| 2472 | + | |
2458 | 2473 |
| |
2459 | 2474 |
| |
2460 | 2475 |
| |
2461 | 2476 |
| |
2462 | 2477 |
| |
2463 | 2478 |
| |
2464 | 2479 |
| |
| 2480 | + | |
| 2481 | + | |
2465 | 2482 |
| |
2466 | 2483 |
| |
2467 | 2484 |
| |
2468 |
| - | |
| 2485 | + | |
2469 | 2486 |
| |
2470 |
| - | |
| 2487 | + | |
2471 | 2488 |
| |
| 2489 | + | |
2472 | 2490 |
| |
| 2491 | + | |
| 2492 | + | |
2473 | 2493 |
| |
2474 | 2494 |
| |
2475 | 2495 |
| |
|
Lines changed: 3 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
26 | 26 |
| |
27 | 27 |
| |
28 | 28 |
| |
| 29 | + | |
| 30 | + | |
| 31 | + | |
29 | 32 |
| |
30 | 33 |
| |
31 | 34 |
| |
|
0 commit comments
Comments
(0)