forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit8d7d219

Amit Kapila
Fix an undetected deadlock due to apply worker.
The apply worker needs to update the state of the subscription tables to'READY' during the synchronization phase which requires locking thecorresponding subscription. The apply worker also waits for thesubscription tables to reach the 'SYNCDONE' state after holding the lockson the subscription and the wait is done using WaitLatch. The 'SYNCDONE'state is changed by tablesync workers again by locking the correspondingsubscription. Both the state updates use AccessShareLock mode to lock thesubscription, so they can't block each other. However, a backend cansimultaneously try to acquire a lock on the same subscription usingAccessExclusiveLock mode to alter the subscription. Now, the backend'swait on a lock can sneak in between the apply worker and table sync workercausing deadlock.In other words, apply_worker waits for tablesync worker which waits forbackend, and backend waits for apply worker. This is not detected by thedeadlock detector because apply worker uses WaitLatch.The fix is to release existing locks in apply worker before it starts towait for tablesync worker to change the state.Reported-by: Tomas VondraAuthor: Shlok KyalReviewed-by: Amit Kapila, Peter SmithBackpatch-through: 12Discussion:https://postgr.es/m/d291bb50-12c4-e8af-2af2-7bb9bb4d8e3e@enterprisedb.com1 parent90834ce commit8d7d219
1 file changed
+15
-5
lines changedLines changed: 15 additions & 5 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
541 | 541 |
| |
542 | 542 |
| |
543 | 543 |
| |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
544 | 557 |
| |
545 | 558 |
| |
546 | 559 |
| |
547 | 560 |
| |
548 |
| - | |
549 |
| - | |
550 |
| - | |
551 |
| - | |
552 |
| - | |
| 561 | + | |
| 562 | + | |
553 | 563 |
| |
554 | 564 |
| |
555 | 565 |
| |
|
0 commit comments
Comments
(0)