Fix race condition at backend exit when deleting element in syncrep queue
authorMichael Paquier <[email protected]>
Fri, 1 Nov 2019 13:39:05 +0000 (22:39 +0900)
committerMichael Paquier <[email protected]>
Fri, 1 Nov 2019 13:39:05 +0000 (22:39 +0900)
commit0927d0c25c567564f1ce24ab9d8d6f1c5d83f1f0
tree7272426c5c6fed39d85db2ce5179cfa76871d886
parent39ff656a415118cdd8231ee524aeed67796062a4
Fix race condition at backend exit when deleting element in syncrep queue

When a backend exits, it gets deleted from the syncrep queue if present.
The queue was checked without SyncRepLock taken in exclusive mode, so it
would have been possible for a backend to remove itself after a WAL
sender already did the job.  Fix this issue based on a suggestion from
Fujii Masao, by first checking the queue without the lock.  Then, if the
backend is present in the queue, take the lock and perform an additional
lookup check before doing the element deletion.

Author: Dongming Liu
Reviewed-by: Kyotaro Horiguchi, Fujii Masao, Michael Paquier
Discussion: https://postgr.es/m/a0806273-8bbb-43b3-bbe1-c45a58f6ae21[email protected]
Backpatch-through: 9.4
src/backend/replication/syncrep.c