From: Oleksandr Shulgin <oleksandr.shulgin@zalando.de>
To: Michael Paquier <michael.paquier@gmail.com>
Cc: hlinnaka@iki.fi, Tom Lane <tgl@sss.pgh.pa.us>
Cc: Pg Bugs <pgsql-bugs@postgresql.org>
Subject: Re: PQexec() hangs on OOM
Date: Wed, 20 May 2015 18:31:10 +0200
Message-ID: <87wq03rz1t.fsf@ashulgin01.corp.ad.zalando.net> (raw)
In-Reply-To: <CAB7nPqQBPSwz+g2BN5HQyUiMEUY-Scr9jm7RyBSOeo00HFo3gw@mail.gmail.com>
References: <547480DE.4040408@vmware.com>
<CAB7nPqR8UtXpTOkKOuxhhXM8PzcPa4dQDKE6rYx+tZhPrQQNWg@mail.gmail.com>
<CAB7nPqSb3RF=s+BDyq1Un2+rng20EQQyxajdTRtpRG7XsyuLnw@mail.gmail.com>
<25150.1428328002@sss.pgh.pa.us>
<CAB7nPqQPaDb+=GCkdZb1L-VbpJTiigPx9_UNTA1a4H2MLGi9XA@mail.gmail.com>
<552427FC.6060302@iki.fi>
<CAB7nPqTqJmUL_jmATPvXzfET9u6DFQxtvF2J74D7XO6QebyAEw@mail.gmail.com>
<5526BA0A.4090600@iki.fi>
<CAB7nPqQBPSwz+g2BN5HQyUiMEUY-Scr9jm7RyBSOeo00HFo3gw@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
Michael Paquier <michael.paquier@gmail.com> writes:
>
>> There are still a few parseInput subroutines that have similar issues. In
>> fe-protocol2.c:
>>
>> * pqGetErrorNotice2 returns EOF if there is not enough data, but also on
>> OOM. The caller assumes it's because not enough data.
>> * getRowDescriptions() is the same, although it sets conn->errorMessage on
>> OOM.
>
> OK, I extended those two with the same logic as previously.
>
>> * getAnotherTuple() is the same, but it also skips over the received data,
>> so you won't get stuck. So maybe that's OK.
>
> I think that it should be changed for consistency with the others, so
> done this way for this function, and this way we only need to bail-out
> if status == -2, a status of -1 meaning that there is not enough data.
>
>> * getNotify() just drops any NOTIFY messages on OOM. Perhaps that's OK..
>
> This one is different though, it directly skips the messages.
>
>> The corresponding functions in fe-protocol3.c are pretty much identical,
>> with the same issues. In addition:
>>
>> * getParameterStatus will act as if the parameter value was "out of memory".
>> That'll be fun for something like client_encoding or
>> standard_conforming_strings. Would be good to use a small char[100]
>> variable, in stack, if it fits, and only use malloc for larger values. That
>> would cover all the common variables that need to be machine-parsed.
>
> Are you suggesting to replace PQExpBuffer?
>
> So, attached is take three for all the other things above.
There's still one call to pqGetErrorNotice3 that doesn't check returned
value for -2, in fe-connect.c. Shouldn't we also check it like this:
inline patch 1: src/interfaces/libpq/fe-connect.c (+9/-1 lines) download inline-1.patchdiff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.cindex e7c7a25..330b8da 100644--- a/src/interfaces/libpq/fe-connect.c+++ b/src/interfaces/libpq/fe-connect.c@@ -2242,6 +2242,7 @@ keep_going: /* We will come back to here until there is
int msgLength;
int avail;
AuthRequest areq;
+ int res;
/*
* Scan the message from current point (note that if we find
@@ -2366,11 +2367,18 @@ keep_going: /* We will come back to here until there is
{
if (PG_PROTOCOL_MAJOR(conn->pversion) >= 3)
{
- if (pqGetErrorNotice3(conn, true))+ res = pqGetErrorNotice3(conn, true);+ if (res == -1)
{
/* We'll come back when there is more data */
return PGRES_POLLING_READING;
}
+ else if (res == -2)+ {+ printfPQExpBuffer(&conn->errorMessage,+ libpq_gettext("out of memory\n"));+ goto error_return;+ }
}
else
{
--
Alex
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: oleksandr.shulgin@zalando.de, michael.paquier@gmail.com, tgl@sss.pgh.pa.us
Subject: Re: PQexec() hangs on OOM
In-Reply-To: <87wq03rz1t.fsf@ashulgin01.corp.ad.zalando.net>
References: <547480DE.4040408@vmware.com> <CAB7nPqR8UtXpTOkKOuxhhXM8PzcPa4dQDKE6rYx+tZhPrQQNWg@mail.gmail.com> <CAB7nPqSb3RF=s+BDyq1Un2+rng20EQQyxajdTRtpRG7XsyuLnw@mail.gmail.com> <25150.1428328002@sss.pgh.pa.us> <CAB7nPqQPaDb+=GCkdZb1L-VbpJTiigPx9_UNTA1a4H2MLGi9XA@mail.gmail.com> <552427FC.6060302@iki.fi> <CAB7nPqTqJmUL_jmATPvXzfET9u6DFQxtvF2J74D7XO6QebyAEw@mail.gmail.com> <5526BA0A.4090600@iki.fi> <CAB7nPqQBPSwz+g2BN5HQyUiMEUY-Scr9jm7RyBSOeo00HFo3gw@mail.gmail.com> <87wq03rz1t.fsf@ashulgin01.corp.ad.zalando.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox