Re: PQexec() hangs on OOM

From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
Cc: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Oleksandr Shulgin <oleksandr(dot)shulgin(at)zalando(dot)de>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Pg Bugs <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: PQexec() hangs on OOM
Date: 2015-09-13 22:57:11
Message-ID: CAB7nPqSr2rEe0pHTkbCeVDpubM7jSZs-V5HvF-3Yhgexrz1z2Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Sat, Sep 12, 2015 at 5:56 PM, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com> wrote:
> On Mon, Sep 7, 2015 at 8:43 PM, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
> wrote:
>>
>> On Mon, Sep 7, 2015 at 10:41 PM, Michael Paquier wrote:
>> > In any case, attached are two patches:
>> > - 0001 adds the OOM/failure handling for the BIND and COPY start
>> > messages. This time the connection is not dropped. After a failure,
>> > successive commands work as well, this addresses the previous issue
>> > you reported.
>> > - 0002 is a cleanup bonus, getRowDescriptions and getAnotherTuple have
>> > some dead code that I think would be better removed, those are
>> > remnants from a copy/paste from the similar code of protocol 2.
>>
>> And I forgot... Attached is a simple program to test BIND messages.
>
>
> Still the same test fails for me.
>
> postgres=# copy t1 from stdin;
> out of memory
> postgres=# copy t1 from stdin; --hangs here
>
> It hangs in second statement, basically I think you can't change the
> state to PGASYNC_BUSY on failure in case of copy in below code.
>
> + case PGASYNC_FATAL:
> + res = NULL;
> + /*
> + * Set the state back to BUSY, allowing parsing to proceed to
> + * consume messages coming from the server.
> + */
> + conn->asyncStatus = PGASYNC_BUSY;
> + break;
>
> I think you need to keep the state as PGASYNC_COPY_*, so that
> the pending data can be discarded.

Yes right. And my patch was as well broken with PGRES_COPY_BOTH. If
the replication protocol expected to wait for some data, this would
have frozen as well as it's a two-way data exchange in this case.
--
Michael

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Michael Paquier 2015-09-14 01:36:32 Re: PQexec() hangs on OOM
Previous Message yoonghm 2015-09-13 16:32:51 BUG #13617: ecpg cannot handle boolean field within a structure