Re: pgsql: Avoid spurious deadlocks when upgrading a tuple lock
Alvaro Herrera <alvherre@2ndquadrant.com>
From: Alvaro Herrera <alvherre@2ndquadrant.com>
To: Oleksii Kliukin <alexk@hintbits.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>, pgsql-hackers@lists.postgresql.org
Date: 2019-06-15T22:47:13Z
Lists: pgsql-hackers
On 2019-Jun-16, Oleksii Kliukin wrote: > Alvaro Herrera <alvherre@2ndquadrant.com> wrote: > > > On 2019-Jun-14, Alvaro Herrera wrote: > > > >> I think there are worse problems here. I tried the attached isolation > >> spec. Note that the only difference in the two permutations is that s0 > >> finishes earlier in one than the other; yet the first one works fine and > >> the second one hangs until killed by the 180s timeout. (s3 isn't > >> released for a reason I'm not sure I understand.) > > > > Actually, those behaviors both seem correct to me now that I look > > closer. So this was a false alarm. In the code before de87a084c0, the > > first permutation deadlocks, and the second permutation hangs. The only > > behavior change is that the first one no longer deadlocks, which is the > > desired change. > > > > I'm still trying to form a case to exercise the case of skip_tuple_lock > > having the wrong lifetime. > > Hm… I think it was an oversight from my part not to give skip_lock_tuple the > same lifetime as have_tuple_lock or first_time (also initializing it to > false at the same time). Even if now it might not break anything in an > obvious way, a backward jump to l3 label will leave skip_lock_tuple > uninitialized, making it very dangerous for any future code that will rely > on its value. But that's not the danger ... with the current coding, it's initialized to false every time through that block; that means the tuple lock will never be skipped if we jump back to l3. So the danger is that the first iteration sets the variable, then jumps back; second iteration initializes the variable again, so instead of skipping the lock, it takes it, causing a spurious deadlock. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Commits
-
Avoid spurious deadlocks when upgrading a tuple lock
- 8b21b416ed62 12.0 landed
- 5246d3e79103 11.5 landed
- 0ba35c7c9f8e 9.6.15 landed
- 0772d8a00eb8 10.10 landed
- de87a084c0a5 12.0 cited
-
Revert "Avoid spurious deadlocks when upgrading a tuple lock"
- 9d20b0ec8f2a 12.0 landed
- 28dc2c25c579 11.4 landed
- 93d4484ef80a 10.9 landed
- 03964e58efb8 9.6.14 landed
-
Silence compiler warning
- 3da73d6839dc 12.0 cited