Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cWlFo-0001oG-7A for pgsql-bugs@arkaria.postgresql.org; Thu, 26 Jan 2017 14:42:24 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cWlFn-0002Hj-QI for pgsql-bugs@arkaria.postgresql.org; Thu, 26 Jan 2017 14:42:23 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cWkoL-0003Wd-Rx for pgsql-bugs@postgresql.org; Thu, 26 Jan 2017 14:14:01 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cWkoE-00048Z-C0 for pgsql-bugs@postgresql.org; Thu, 26 Jan 2017 14:14:01 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id v0QEDq2T032199; Thu, 26 Jan 2017 09:13:52 -0500 From: Tom Lane To: andrew@tao11.riddles.org.uk cc: pgsql-bugs@postgresql.org Subject: Re: BUG #14516: misleading error from libpq on out-of-memory In-reply-to: <20170126050259.1434.30111@wrigleys.postgresql.org> References: <20170126050259.1434.30111@wrigleys.postgresql.org> Comments: In-reply-to andrew@tao11.riddles.org.uk message dated "Thu, 26 Jan 2017 05:02:59 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <32197.1485440032.1@sss.pgh.pa.us> Date: Thu, 26 Jan 2017 09:13:52 -0500 Message-ID: <32198.1485440032@sss.pgh.pa.us> X-Pg-Spam-Score: -5.1 (-----) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org 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