Re: Problem with synchronous replication
lingce.ldm <lingce.ldm@alibaba-inc.com>
From: lingce.ldm <lingce.ldm@alibaba-inc.com>
To: Michael Paquier <michael@paquier.xyz>
Cc: Kyotaro Horiguchi <horikyota.ntt@gmail.com>,
pgsql-hackers@postgresql.org
Date: 2019-10-30T06:27:46Z
Lists: pgsql-hackers
On Oct 30, 2019, at 09:45, Michael Paquier <michael@paquier.xyz <mailto:michael@paquier.xyz>> wrote: > > On Tue, Oct 29, 2019 at 07:50:01PM +0900, Kyotaro Horiguchi wrote: >> At Fri, 25 Oct 2019 15:18:34 +0800, "Dongming Liu" <lingce.ldm@alibaba-inc.com> wrote in >>> I recently discovered two possible bugs about synchronous replication. >>> >>> 1. SyncRepCleanupAtProcExit may delete an element that has been deleted >>> SyncRepCleanupAtProcExit first checks whether the queue is detached, if it is not detached, >>> acquires the SyncRepLock lock and deletes it. If this element has been deleted by walsender, >>> it will be deleted repeatedly, SHMQueueDelete will core with a segment fault. >>> >>> IMO, like SyncRepCancelWait, we should lock the SyncRepLock first and then check >>> whether the queue is detached or not. >> >> I think you're right here. > > Indeed. Looking at the surroundings we expect some code paths to hold > SyncRepLock in exclusive or shared mode but we don't actually check > that the lock is hold. So let's add some assertions while on it. > >> This is not right. It is in transaction commit so it is in a >> HOLD_INTERRUPTS section. ProcessInterrupt does not respond to >> cancel/die interrupts thus the ereport should return. > > Yeah. There is an easy way to check after that: InterruptHoldoffCount > needs to be strictly positive. > > My suggestions are attached. Any thoughts? Thanks, this patch looks good to me.
Commits
-
Add some assertions in syncrep.c
- e174f699c476 13.0 landed
-
Fix race condition at backend exit when deleting element in syncrep queue
- f88f7206edbf 9.4.25 landed
- 0927d0c25c56 9.5.20 landed
- 52684bc7d957 9.6.16 landed
- b99bfc3c96f1 10.11 landed
- 61f23839257d 11.6 landed
- 7b8c2de64e66 12.1 landed
- 20345197ff48 13.0 landed
-
Fix typo in comment of syncrep.c
- f921ea624eb8 13.0 landed