]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix race condition at backend exit when deleting element in syncrep queue
authorMichael Paquier <michael@paquier.xyz>
Fri, 1 Nov 2019 13:38:55 +0000 (22:38 +0900)
committerMichael Paquier <michael@paquier.xyz>
Fri, 1 Nov 2019 13:38:55 +0000 (22:38 +0900)
commitb99bfc3c96f16c4e08bc1276cee95f01bcc09bf3
tree9b9e3f5061613d71f233d0e049757c3987139919
parent82200115e05501c633595c2a7b61143f0e610a00
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.lingce.ldm@alibaba-inc.com
Backpatch-through: 9.4
src/backend/replication/syncrep.c