forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commita1a789e
committed
In walreceiver, don't try to do ereport() in a signal handler.
This is quite unsafe, even for the case of ereport(FATAL) where we won'treturn control to the interrupted code, and despite this code's use ofa flag to restrict the areas where we'd try to do it. It's possiblefor example that we interrupt malloc or free while that's holding a lockthat's meant to protect against cross-thread interference. Then, anyattempt to do malloc or free within ereport() will result in a deadlock,preventing the walreceiver process from exiting in response to SIGTERM.We hypothesize that this explains some hard-to-reproduce failures seenin the buildfarm.Hence, get rid of the immediate-exit code in WalRcvShutdownHandler,as well as the logic associated with WalRcvImmediateInterruptOK.Instead, we need to take care that potentially-blocking operationsin the walreceiver's data transmission logic (libpqwalreceiver.c)will respond reasonably promptly to the process's latch becomingset and then call ProcessWalRcvInterrupts. Much of the needed codefor that was already present in libpqwalreceiver.c. I refactoredthings a bit so that all the uses of PQgetResult use latch-awarewaiting, but didn't need to do much more.These changes should be enough to ensure that libpqwalreceiver.cwill respond promptly to SIGTERM whenever it's waiting to receivedata. In principle, it could block for a long time while waitingto send data too, and this patch does nothing to guard against that.I think that that hazard is mostly theoretical though: such blockingshould occur only if we fill the kernel's data transmission buffers,and we don't generally send enough data to make that happen withoutwaiting for input. If we find out that the hazard isn't justtheoretical, we could fix it by using PQsetnonblocking, but thatwould require more ticklish changes than I care to make now.This is a bug fix, but it seems like too big a change to push intothe back branches without much more testing than there's time forright now. Perhaps we'll back-patch once we have more confidencein the change.Patch by me; thanks to Thomas Munro for review.Discussion:https://postgr.es/m/20190416070119.GK2673@paquier.xyz1 parent9c59289 commita1a789e
File tree
3 files changed
+85
-101
lines changed- src
- backend/replication
- libpqwalreceiver
- include/replication
3 files changed
+85
-101
lines changedLines changed: 67 additions & 52 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
99 | 99 |
| |
100 | 100 |
| |
101 | 101 |
| |
| 102 | + | |
102 | 103 |
| |
103 | 104 |
| |
104 | 105 |
| |
| |||
196 | 197 |
| |
197 | 198 |
| |
198 | 199 |
| |
199 |
| - | |
| 200 | + | |
200 | 201 |
| |
201 | 202 |
| |
202 | 203 |
| |
| |||
456 | 457 |
| |
457 | 458 |
| |
458 | 459 |
| |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
459 | 464 |
| |
460 | 465 |
| |
461 | 466 |
| |
| |||
472 | 477 |
| |
473 | 478 |
| |
474 | 479 |
| |
475 |
| - | |
| 480 | + | |
476 | 481 |
| |
477 | 482 |
| |
478 | 483 |
| |
| |||
486 | 491 |
| |
487 | 492 |
| |
488 | 493 |
| |
489 |
| - | |
| 494 | + | |
490 | 495 |
| |
491 | 496 |
| |
492 | 497 |
| |
| |||
499 | 504 |
| |
500 | 505 |
| |
501 | 506 |
| |
502 |
| - | |
| 507 | + | |
503 | 508 |
| |
504 | 509 |
| |
505 | 510 |
| |
| |||
509 | 514 |
| |
510 | 515 |
| |
511 | 516 |
| |
512 |
| - | |
| 517 | + | |
513 | 518 |
| |
514 | 519 |
| |
515 | 520 |
| |
| |||
572 | 577 |
| |
573 | 578 |
| |
574 | 579 |
| |
575 |
| - | |
| 580 | + | |
576 | 581 |
| |
577 | 582 |
| |
578 | 583 |
| |
579 | 584 |
| |
580 |
| - | |
581 | 585 |
| |
582 | 586 |
| |
583 | 587 |
| |
| |||
588 | 592 |
| |
589 | 593 |
| |
590 | 594 |
| |
591 |
| - | |
592 |
| - | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
593 | 598 |
| |
594 | 599 |
| |
595 | 600 |
| |
596 | 601 |
| |
597 | 602 |
| |
598 | 603 |
| |
599 |
| - | |
600 |
| - | |
601 |
| - | |
602 |
| - | |
603 |
| - | |
604 |
| - | |
605 |
| - | |
606 |
| - | |
607 |
| - | |
608 |
| - | |
609 |
| - | |
610 |
| - | |
611 |
| - | |
612 |
| - | |
613 |
| - | |
614 |
| - | |
615 |
| - | |
616 |
| - | |
617 |
| - | |
618 |
| - | |
619 |
| - | |
620 |
| - | |
621 |
| - | |
622 |
| - | |
623 |
| - | |
624 |
| - | |
625 |
| - | |
626 |
| - | |
| 604 | + | |
| 605 | + | |
627 | 606 |
| |
628 |
| - | |
629 |
| - | |
630 |
| - | |
631 |
| - | |
632 |
| - | |
633 |
| - | |
634 |
| - | |
635 |
| - | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
636 | 610 |
| |
637 | 611 |
| |
638 | 612 |
| |
639 | 613 |
| |
640 | 614 |
| |
641 |
| - | |
642 |
| - | |
643 |
| - | |
644 |
| - | |
645 | 615 |
| |
646 | 616 |
| |
647 | 617 |
| |
| |||
655 | 625 |
| |
656 | 626 |
| |
657 | 627 |
| |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
658 | 673 |
| |
659 | 674 |
| |
660 | 675 |
| |
| |||
716 | 731 |
| |
717 | 732 |
| |
718 | 733 |
| |
719 |
| - | |
| 734 | + | |
720 | 735 |
| |
721 | 736 |
| |
722 | 737 |
| |
723 | 738 |
| |
724 | 739 |
| |
725 |
| - | |
| 740 | + | |
726 | 741 |
| |
727 | 742 |
| |
728 | 743 |
| |
| |||
886 | 901 |
| |
887 | 902 |
| |
888 | 903 |
| |
889 |
| - | |
| 904 | + | |
890 | 905 |
| |
891 | 906 |
| |
892 | 907 |
| |
|
Lines changed: 17 additions & 49 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
112 | 112 |
| |
113 | 113 |
| |
114 | 114 |
| |
115 |
| - | |
116 |
| - | |
117 |
| - | |
118 |
| - | |
119 |
| - | |
120 |
| - | |
121 |
| - | |
122 |
| - | |
123 |
| - | |
124 |
| - | |
125 |
| - | |
126 |
| - | |
127 |
| - | |
128 |
| - | |
129 |
| - | |
130 |
| - | |
131 |
| - | |
132 |
| - | |
133 | 115 |
| |
134 |
| - | |
135 |
| - | |
136 |
| - | |
137 | 116 |
| |
138 | 117 |
| |
139 | 118 |
| |
| |||
151 | 130 |
| |
152 | 131 |
| |
153 | 132 |
| |
154 |
| - | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
155 | 147 |
| |
156 | 148 |
| |
157 | 149 |
| |
| |||
163 | 155 |
| |
164 | 156 |
| |
165 | 157 |
| |
166 |
| - | |
167 | 158 |
| |
168 | 159 |
| |
169 | 160 |
| |
170 | 161 |
| |
171 | 162 |
| |
172 | 163 |
| |
173 |
| - | |
174 |
| - | |
175 |
| - | |
176 |
| - | |
177 |
| - | |
178 |
| - | |
179 |
| - | |
180 |
| - | |
181 |
| - | |
182 |
| - | |
183 |
| - | |
184 |
| - | |
185 |
| - | |
186 | 164 |
| |
187 | 165 |
| |
188 | 166 |
| |
| |||
292 | 270 |
| |
293 | 271 |
| |
294 | 272 |
| |
295 |
| - | |
296 | 273 |
| |
297 | 274 |
| |
298 | 275 |
| |
299 | 276 |
| |
300 |
| - | |
301 | 277 |
| |
302 | 278 |
| |
303 | 279 |
| |
| |||
336 | 312 |
| |
337 | 313 |
| |
338 | 314 |
| |
339 |
| - | |
340 | 315 |
| |
341 | 316 |
| |
342 | 317 |
| |
| |||
348 | 323 |
| |
349 | 324 |
| |
350 | 325 |
| |
351 |
| - | |
352 | 326 |
| |
353 | 327 |
| |
354 | 328 |
| |
| |||
509 | 483 |
| |
510 | 484 |
| |
511 | 485 |
| |
| 486 | + | |
| 487 | + | |
512 | 488 |
| |
513 | 489 |
| |
514 | 490 |
| |
| |||
577 | 553 |
| |
578 | 554 |
| |
579 | 555 |
| |
580 |
| - | |
581 | 556 |
| |
582 |
| - | |
583 | 557 |
| |
584 | 558 |
| |
585 | 559 |
| |
| |||
726 | 700 |
| |
727 | 701 |
| |
728 | 702 |
| |
729 |
| - | |
730 | 703 |
| |
731 |
| - | |
732 | 704 |
| |
733 | 705 |
| |
734 | 706 |
| |
| |||
805 | 777 |
| |
806 | 778 |
| |
807 | 779 |
| |
808 |
| - | |
| 780 | + | |
809 | 781 |
| |
810 | 782 |
| |
811 | 783 |
| |
| |||
816 | 788 |
| |
817 | 789 |
| |
818 | 790 |
| |
819 |
| - | |
820 |
| - | |
821 |
| - | |
822 |
| - | |
823 | 791 |
| |
824 | 792 |
| |
825 | 793 |
| |
|
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
302 | 302 |
| |
303 | 303 |
| |
304 | 304 |
| |
| 305 | + | |
305 | 306 |
| |
306 | 307 |
| |
307 | 308 |
| |
|
0 commit comments
Comments
(0)