From: Tom Lane <tgl@sss.pgh.pa.us>
To: andrew@tao11.riddles.org.uk
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #14516: misleading error from libpq on out-of-memory
Date: Thu, 26 Jan 2017 09:13:52 -0500
Message-ID: <32198.1485440032@sss.pgh.pa.us> (raw)
In-Reply-To: <20170126050259.1434.30111@wrigleys.postgresql.org>
References: <20170126050259.1434.30111@wrigleys.postgresql.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
andrew@tao11.riddles.org.uk writes:
> Running psql with a restricted memory ulimit to reproduce, one gets this
> error message:
> postgres=# \copy (select repeat('a',120000000)) to '/dev/null'
> lost synchronization with server: got message type "d", length 120000001
Yeah. Per the code comments:
/*
* Before returning, enlarge the input buffer if needed to hold
* the whole message. ...
*/
if (pqCheckInBufferSpace(conn->inCursor + (size_t) msgLength,
conn))
{
/*
* XXX add some better recovery code... plan is to skip over
* the message using its length, then report an error. For the
* moment, just treat this like loss of sync (which indeed it
* might be!)
*/
handleSyncLoss(conn, id, msgLength);
}
The point being that if we lost sync with the message stream, the symptom
from this code's point of view would be a garbage header for the next
message, which would include a possibly-bogus message type code and a
definitely-insane-looking length. There's a sanity check involving
VALID_LONG_MESSAGE_TYPE ahead of this, but with seven such message types,
the odds of getting past that are not negligible.
In short, it's not that easy to do better. Given the infrequency of
complaints, I'm not sure it's worth spending time on. (The code in
question has been like that since we started using message length words,
in 2003; cf 5ed27e35f35f6c354b1a7120ec3a3ce57f93e73e. I don't think
it's come up more than a couple of times since then.)
regards, tom lane
--
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: tgl@sss.pgh.pa.us, andrew@tao11.riddles.org.uk
Subject: Re: BUG #14516: misleading error from libpq on out-of-memory
In-Reply-To: <32198.1485440032@sss.pgh.pa.us>
References: <20170126050259.1434.30111@wrigleys.postgresql.org> <32198.1485440032@sss.pgh.pa.us>
* 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