forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitac8f2e1
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.Back-patch of commita1a789e. This problem goes all the way backto the origins of walreceiver; but given the substantial reworkingthe module received during the v10 cycle, it seems unsafe to assumethat our testing on HEAD validates this patch for pre-v10 branches.And we'd need to back-patch some prerequisite patches (at least597a87c and its followups, maybe other things), increasing the riskof problems. Given the dearth of field reports matching this problem,it's not worth much risk. Hence back-patch to v10 and v11 only.Patch by me; thanks to Thomas Munro for review.Discussion:https://postgr.es/m/20190416070119.GK2673@paquier.xyz1 parent2981e5a commitac8f2e1
File tree
3 files changed
+89
-105
lines changed- src
- backend/replication
- libpqwalreceiver
- include/replication
3 files changed
+89
-105
lines changedLines changed: 71 additions & 56 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
95 | 95 |
| |
96 | 96 |
| |
97 | 97 |
| |
| 98 | + | |
98 | 99 |
| |
99 | 100 |
| |
100 | 101 |
| |
| |||
196 | 197 |
| |
197 | 198 |
| |
198 | 199 |
| |
199 |
| - | |
| 200 | + | |
200 | 201 |
| |
201 | 202 |
| |
202 | 203 |
| |
| |||
427 | 428 |
| |
428 | 429 |
| |
429 | 430 |
| |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
430 | 435 |
| |
431 | 436 |
| |
432 | 437 |
| |
| |||
443 | 448 |
| |
444 | 449 |
| |
445 | 450 |
| |
446 |
| - | |
| 451 | + | |
447 | 452 |
| |
448 | 453 |
| |
449 | 454 |
| |
| |||
457 | 462 |
| |
458 | 463 |
| |
459 | 464 |
| |
460 |
| - | |
| 465 | + | |
461 | 466 |
| |
462 | 467 |
| |
463 | 468 |
| |
| |||
470 | 475 |
| |
471 | 476 |
| |
472 | 477 |
| |
473 |
| - | |
| 478 | + | |
474 | 479 |
| |
475 | 480 |
| |
476 | 481 |
| |
| |||
480 | 485 |
| |
481 | 486 |
| |
482 | 487 |
| |
483 |
| - | |
| 488 | + | |
484 | 489 |
| |
485 | 490 |
| |
486 | 491 |
| |
| |||
543 | 548 |
| |
544 | 549 |
| |
545 | 550 |
| |
546 |
| - | |
| 551 | + | |
547 | 552 |
| |
548 | 553 |
| |
549 | 554 |
| |
550 | 555 |
| |
551 |
| - | |
552 | 556 |
| |
553 | 557 |
| |
554 | 558 |
| |
| |||
559 | 563 |
| |
560 | 564 |
| |
561 | 565 |
| |
562 |
| - | |
563 |
| - | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
564 | 569 |
| |
565 | 570 |
| |
566 | 571 |
| |
567 | 572 |
| |
568 | 573 |
| |
569 | 574 |
| |
570 |
| - | |
571 |
| - | |
572 |
| - | |
573 |
| - | |
574 |
| - | |
575 |
| - | |
576 |
| - | |
577 |
| - | |
578 |
| - | |
579 |
| - | |
580 |
| - | |
581 |
| - | |
582 |
| - | |
583 |
| - | |
584 |
| - | |
585 |
| - | |
586 |
| - | |
587 |
| - | |
588 |
| - | |
589 |
| - | |
590 |
| - | |
591 |
| - | |
592 |
| - | |
593 |
| - | |
594 |
| - | |
595 |
| - | |
596 |
| - | |
597 |
| - | |
598 |
| - | |
599 |
| - | |
600 |
| - | |
601 |
| - | |
| 575 | + | |
| 576 | + | |
602 | 577 |
| |
603 |
| - | |
604 |
| - | |
605 |
| - | |
606 |
| - | |
607 |
| - | |
608 |
| - | |
609 |
| - | |
610 |
| - | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
611 | 581 |
| |
612 | 582 |
| |
613 | 583 |
| |
614 | 584 |
| |
615 | 585 |
| |
616 |
| - | |
617 |
| - | |
618 |
| - | |
619 |
| - | |
620 | 586 |
| |
621 | 587 |
| |
622 | 588 |
| |
| |||
630 | 596 |
| |
631 | 597 |
| |
632 | 598 |
| |
| 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 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
633 | 648 |
| |
634 | 649 |
| |
635 | 650 |
| |
| |||
691 | 706 |
| |
692 | 707 |
| |
693 | 708 |
| |
694 |
| - | |
| 709 | + | |
695 | 710 |
| |
696 | 711 |
| |
697 | 712 |
| |
698 | 713 |
| |
699 | 714 |
| |
700 |
| - | |
| 715 | + | |
701 | 716 |
| |
702 | 717 |
| |
703 | 718 |
| |
| |||
861 | 876 |
| |
862 | 877 |
| |
863 | 878 |
| |
864 |
| - | |
| 879 | + | |
865 | 880 |
| |
866 | 881 |
| |
867 | 882 |
| |
|
Lines changed: 17 additions & 49 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
111 | 111 |
| |
112 | 112 |
| |
113 | 113 |
| |
114 |
| - | |
115 |
| - | |
116 |
| - | |
117 |
| - | |
118 |
| - | |
119 |
| - | |
120 |
| - | |
121 |
| - | |
122 |
| - | |
123 |
| - | |
124 |
| - | |
125 |
| - | |
126 |
| - | |
127 |
| - | |
128 |
| - | |
129 |
| - | |
130 |
| - | |
131 |
| - | |
132 | 114 |
| |
133 |
| - | |
134 |
| - | |
135 |
| - | |
136 | 115 |
| |
137 | 116 |
| |
138 | 117 |
| |
| |||
150 | 129 |
| |
151 | 130 |
| |
152 | 131 |
| |
153 |
| - | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
154 | 146 |
| |
155 | 147 |
| |
156 | 148 |
| |
| |||
162 | 154 |
| |
163 | 155 |
| |
164 | 156 |
| |
165 |
| - | |
166 | 157 |
| |
167 | 158 |
| |
168 | 159 |
| |
169 | 160 |
| |
170 | 161 |
| |
171 | 162 |
| |
172 |
| - | |
173 |
| - | |
174 |
| - | |
175 |
| - | |
176 |
| - | |
177 |
| - | |
178 |
| - | |
179 |
| - | |
180 |
| - | |
181 |
| - | |
182 |
| - | |
183 |
| - | |
184 |
| - | |
185 | 163 |
| |
186 | 164 |
| |
187 | 165 |
| |
| |||
299 | 277 |
| |
300 | 278 |
| |
301 | 279 |
| |
302 |
| - | |
303 | 280 |
| |
304 | 281 |
| |
305 | 282 |
| |
306 | 283 |
| |
307 |
| - | |
308 | 284 |
| |
309 | 285 |
| |
310 | 286 |
| |
| |||
333 | 309 |
| |
334 | 310 |
| |
335 | 311 |
| |
336 |
| - | |
337 | 312 |
| |
338 | 313 |
| |
339 | 314 |
| |
| |||
346 | 321 |
| |
347 | 322 |
| |
348 | 323 |
| |
349 |
| - | |
350 | 324 |
| |
351 | 325 |
| |
352 | 326 |
| |
| |||
507 | 481 |
| |
508 | 482 |
| |
509 | 483 |
| |
| 484 | + | |
| 485 | + | |
510 | 486 |
| |
511 | 487 |
| |
512 | 488 |
| |
| |||
584 | 560 |
| |
585 | 561 |
| |
586 | 562 |
| |
587 |
| - | |
588 | 563 |
| |
589 |
| - | |
590 | 564 |
| |
591 | 565 |
| |
592 | 566 |
| |
| |||
740 | 714 |
| |
741 | 715 |
| |
742 | 716 |
| |
743 |
| - | |
744 | 717 |
| |
745 |
| - | |
746 | 718 |
| |
747 | 719 |
| |
748 | 720 |
| |
| |||
819 | 791 |
| |
820 | 792 |
| |
821 | 793 |
| |
822 |
| - | |
| 794 | + | |
823 | 795 |
| |
824 | 796 |
| |
825 | 797 |
| |
| |||
830 | 802 |
| |
831 | 803 |
| |
832 | 804 |
| |
833 |
| - | |
834 |
| - | |
835 |
| - | |
836 |
| - | |
837 | 805 |
| |
838 | 806 |
| |
839 | 807 |
| |
|
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
285 | 285 |
| |
286 | 286 |
| |
287 | 287 |
| |
| 288 | + | |
288 | 289 |
| |
289 | 290 |
| |
290 | 291 |
| |
|
0 commit comments
Comments
(0)