forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit7519bd1
committed
Fix race condition between shutdown and unstarted background workers.
If a database shutdown (smart or fast) is commanded between the timesome process decides to request a new background worker and the timethat the postmaster can launch that worker, then nothing happensbecause the postmaster won't launch any bgworkers once it's exitedPM_RUN state. This is fine ... unless the requesting process iswaiting for that worker to finish (or even for it to start); in thatcase the requestor is stuck, and only manual intervention will get usto the point of being able to shut down.To fix, cancel pending requests for workers when the postmaster sendsshutdown (SIGTERM) signals, and similarly cancel any new requests thatarrive after that point. (We can optimize things slightly by onlydoing the cancellation for workers that have waiters.) To fit withinthe existing bgworker APIs, the "cancel" is made to look like theworker was started and immediately stopped, causing deregistration ofthe bgworker entry. Waiting processes would have to deal withpremature worker exit anyway, so this should introduce no bugs thatweren't there before. We do have a side effect that registrationrecords for restartable bgworkers might disappear when theoreticallythey should have remained in place; but since we're shutting down,that shouldn't matter.Back-patch to v10. There might be value in putting this into 9.6as well, but the management of bgworkers is a bit different there(notably see8ff5186) and I'm not convinced it's worth the effortto validate the patch for that branch.Discussion:https://postgr.es/m/661570.1608673226@sss.pgh.pa.us1 parent7e784d1 commit7519bd1
File tree
4 files changed
+90
-20
lines changed- contrib/pg_prewarm
- src
- backend/postmaster
- include/postmaster
4 files changed
+90
-20
lines changedLines changed: 1 addition & 6 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
396 | 396 |
| |
397 | 397 |
| |
398 | 398 |
| |
399 |
| - | |
400 |
| - | |
401 |
| - | |
402 |
| - | |
403 |
| - | |
404 |
| - | |
| 399 | + | |
405 | 400 |
| |
406 | 401 |
| |
407 | 402 |
| |
|
Lines changed: 71 additions & 6 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
231 | 231 |
| |
232 | 232 |
| |
233 | 233 |
| |
234 |
| - | |
235 |
| - | |
236 |
| - | |
237 |
| - | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
238 | 240 |
| |
239 | 241 |
| |
240 |
| - | |
| 242 | + | |
241 | 243 |
| |
242 | 244 |
| |
243 | 245 |
| |
| |||
297 | 299 |
| |
298 | 300 |
| |
299 | 301 |
| |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
300 | 311 |
| |
301 | 312 |
| |
302 | 313 |
| |
| |||
503 | 514 |
| |
504 | 515 |
| |
505 | 516 |
| |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
506 | 557 |
| |
507 | 558 |
| |
508 | 559 |
| |
509 | 560 |
| |
510 | 561 |
| |
511 |
| - | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
512 | 566 |
| |
513 | 567 |
| |
514 | 568 |
| |
| |||
548 | 602 |
| |
549 | 603 |
| |
550 | 604 |
| |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
551 | 610 |
| |
552 | 611 |
| |
553 | 612 |
| |
| |||
1077 | 1136 |
| |
1078 | 1137 |
| |
1079 | 1138 |
| |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
1080 | 1142 |
| |
1081 | 1143 |
| |
1082 | 1144 |
| |
| |||
1119 | 1181 |
| |
1120 | 1182 |
| |
1121 | 1183 |
| |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
1122 | 1187 |
| |
1123 | 1188 |
| |
1124 | 1189 |
| |
|
Lines changed: 16 additions & 7 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
3800 | 3800 |
| |
3801 | 3801 |
| |
3802 | 3802 |
| |
| 3803 | + | |
| 3804 | + | |
| 3805 | + | |
| 3806 | + | |
| 3807 | + | |
| 3808 | + | |
| 3809 | + | |
3803 | 3810 |
| |
3804 | 3811 |
| |
3805 | 3812 |
| |
| |||
5154 | 5161 |
| |
5155 | 5162 |
| |
5156 | 5163 |
| |
5157 |
| - | |
5158 |
| - | |
5159 |
| - | |
5160 |
| - | |
5161 |
| - | |
5162 |
| - | |
5163 |
| - | |
5164 | 5164 |
| |
5165 | 5165 |
| |
5166 | 5166 |
| |
| |||
5206 | 5206 |
| |
5207 | 5207 |
| |
5208 | 5208 |
| |
| 5209 | + | |
5209 | 5210 |
| |
5210 | 5211 |
| |
5211 | 5212 |
| |
| |||
5231 | 5232 |
| |
5232 | 5233 |
| |
5233 | 5234 |
| |
| 5235 | + | |
| 5236 | + | |
| 5237 | + | |
| 5238 | + | |
| 5239 | + | |
| 5240 | + | |
| 5241 | + | |
| 5242 | + | |
5234 | 5243 |
| |
5235 | 5244 |
| |
5236 | 5245 |
| |
|
Lines changed: 2 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
46 | 46 |
| |
47 | 47 |
| |
48 | 48 |
| |
49 |
| - | |
| 49 | + | |
50 | 50 |
| |
51 | 51 |
| |
52 | 52 |
| |
53 | 53 |
| |
| 54 | + | |
54 | 55 |
| |
55 | 56 |
| |
56 | 57 |
| |
|
0 commit comments
Comments
(0)