]> granicus.if.org Git - postgresql/commit
Fix ordering of operations in SyncRepWakeQueue to avoid assertion failure.
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Wed, 12 Jul 2017 12:30:52 +0000 (15:30 +0300)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Wed, 12 Jul 2017 12:35:31 +0000 (15:35 +0300)
commit941188a5ff49c4e042ddd4234c35cf0e1bfd7f19
tree24f8df35626cce7074294684d39901da54a1cb19
parentf1edf84580b1df647ae8b9b37c63f2a5612f8610
Fix ordering of operations in SyncRepWakeQueue to avoid assertion failure.

Commit 14e8803f1 removed the locking in SyncRepWaitForLSN, but that
introduced a race condition, where SyncRepWaitForLSN might see
syncRepState already set to SYNC_REP_WAIT_COMPLETE, but the process was
not yet removed from the queue. That tripped the assertion, that the
process should no longer be in the uqeue. Reorder the operations in
SyncRepWakeQueue to remove the process from the queue first, and update
syncRepState only after that, and add a memory barrier in between to make
sure the operations are made visible to other processes in that order.

Fixes bug #14721 reported by Const Zhang. Analysis and fix by Thomas Munro.
Backpatch down to 9.5, where the locking was removed.

Discussion: https://www.postgresql.org/message-id/20170629023623.1480.26508%40wrigleys.postgresql.org
src/backend/replication/syncrep.c