Re: libpqrcv_PQexec() seems to violate latch protocol

From: Petr Jelinek <petr(dot)jelinek(at)2ndquadrant(dot)com>
To: Andres Freund <andres(at)anarazel(dot)de>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org, Petr Jelinek <petr(at)2ndquadrant(dot)com>, Peter Eisentraut <peter_e(at)gmx(dot)net>
Subject: Re: libpqrcv_PQexec() seems to violate latch protocol
Date: 2017-06-06 21:24:50
Message-ID: 61fca096-9ebd-465f-c69f-f86ea3778c28@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 06/06/17 23:17, Andres Freund wrote:
> On 2017-06-06 17:14:59 -0400, Tom Lane wrote:
>> Andres Freund <andres(at)anarazel(dot)de> writes:
>>> The function in $subject does:
>>
>>> ResetLatch(&MyProc->procLatch);
>>> rc = WaitLatchOrSocket(&MyProc->procLatch,
>>> WL_POSTMASTER_DEATH | WL_SOCKET_READABLE |
>>> WL_LATCH_SET,
>>> PQsocket(streamConn),
>>> 0,
>>> WAIT_EVENT_LIBPQWALRECEIVER);
>>
>> Yeah, this is certainly broken.
>>
>>> Afaict, the ResetLatch() really should just instead be in the if (rc & WL_LATCH_SET) block.
>>
>> And, to be specific, it should be before the CHECK_FOR_INTERRUPTS call,
>> since that is the useful work that we want to be sure occurs after
>> any latch-setting event.
>
> Right. I found a couple more instance of similarly iffy, although not
> quite as broken, patterns in launcher.c. It's easy to get this wrong,
> but it's a lot easy if you do it differently everywhere you use a
> latch. It's not good if code in the same file, by the same author(s),
> has different ways of using latches.

Huh? I see same pattern everywhere in launcher.c, what am I missing?

--
Petr Jelinek http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2017-06-06 21:42:35 Re: PG10 transition tables, wCTEs and multiple operations on the same table
Previous Message Petr Jelinek 2017-06-06 21:21:12 Re: logical replication - still unstable after all these months