forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit5b6289c
committed
Handle elog(FATAL) during ROLLBACK more robustly.
Stress testing by Andreas Seltenreich disclosed longstanding problems thatoccur if a FATAL exit (e.g. due to receipt of SIGTERM) occurs while we aretrying to execute a ROLLBACK of an already-failed transaction. In such acase, xact.c is in TBLOCK_ABORT state, so that AbortOutOfAnyTransactionwould skip AbortTransaction and go straight to CleanupTransaction. Thisled to an assert failure in an assert-enabled build (due to the ROLLBACK'sportal still having a cleanup hook) or without assertions, to a FATAL exitcomplaining about "cannot drop active portal". The latter's notdisastrous, perhaps, but it's messy enough to want to improve it.We don't really want to run all of AbortTransaction in this code path.The minimum required to clean up the open portal safely is to doAtAbort_Memory and AtAbort_Portals. It seems like a good idea todo AtAbort_Memory unconditionally, to be entirely sure that we arestarting with a safe CurrentMemoryContext. That means that if themain loop in AbortOutOfAnyTransaction does nothing, we need an extrastep at the bottom to restore CurrentMemoryContext = TopMemoryContext,which I chose to do by invoking AtCleanup_Memory. This'll result incalling AtCleanup_Memory twice in many of the paths through this function,but that seems harmless and reasonably inexpensive.The original motivation for the assertion in AtCleanup_Portals was thatwe wanted to be sure that any user-defined code executed as a consequenceof the cleanup hook runs during AbortTransaction not CleanupTransaction.That still seems like a valid concern, and now that we've seen one caseof the assertion firing --- which means that exactly that would havehappened in a production build --- let's replace the Assert with a runtimecheck. If we see the cleanup hook still set, we'll emit a WARNING andjust drop the hook unexecuted.This has been like this a long time, so back-patch to all supportedbranches.Discussion:https://postgr.es/m/877ey7bmun.fsf@ansel.ydns.eu1 parent7f1bb1d commit5b6289c
2 files changed
+44
-9
lines changedLines changed: 22 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
4226 | 4226 |
| |
4227 | 4227 |
| |
4228 | 4228 |
| |
| 4229 | + | |
| 4230 | + | |
| 4231 | + | |
4229 | 4232 |
| |
4230 | 4233 |
| |
4231 | 4234 |
| |
| |||
4267 | 4270 |
| |
4268 | 4271 |
| |
4269 | 4272 |
| |
4270 |
| - | |
| 4273 | + | |
| 4274 | + | |
| 4275 | + | |
| 4276 | + | |
| 4277 | + | |
| 4278 | + | |
| 4279 | + | |
| 4280 | + | |
4271 | 4281 |
| |
4272 | 4282 |
| |
4273 | 4283 |
| |
| |||
4290 | 4300 |
| |
4291 | 4301 |
| |
4292 | 4302 |
| |
| 4303 | + | |
| 4304 | + | |
| 4305 | + | |
| 4306 | + | |
| 4307 | + | |
| 4308 | + | |
| 4309 | + | |
| 4310 | + | |
4293 | 4311 |
| |
4294 | 4312 |
| |
4295 | 4313 |
| |
| |||
4298 | 4316 |
| |
4299 | 4317 |
| |
4300 | 4318 |
| |
| 4319 | + | |
| 4320 | + | |
| 4321 | + | |
4301 | 4322 |
| |
4302 | 4323 |
| |
4303 | 4324 |
| |
|
Lines changed: 22 additions & 8 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
415 | 415 |
| |
416 | 416 |
| |
417 | 417 |
| |
418 |
| - | |
419 |
| - | |
| 418 | + | |
| 419 | + | |
420 | 420 |
| |
421 | 421 |
| |
422 | 422 |
| |
| |||
443 | 443 |
| |
444 | 444 |
| |
445 | 445 |
| |
446 |
| - | |
447 |
| - | |
| 446 | + | |
| 447 | + | |
448 | 448 |
| |
449 | 449 |
| |
450 | 450 |
| |
| |||
842 | 842 |
| |
843 | 843 |
| |
844 | 844 |
| |
845 |
| - | |
846 |
| - | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
847 | 854 |
| |
848 | 855 |
| |
849 | 856 |
| |
| |||
1026 | 1033 |
| |
1027 | 1034 |
| |
1028 | 1035 |
| |
1029 |
| - | |
1030 |
| - | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
1031 | 1045 |
| |
1032 | 1046 |
| |
1033 | 1047 |
| |
|
0 commit comments
Comments
(0)