Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XfeVe-0001Oj-B8 for pgsql-bugs@arkaria.postgresql.org; Sun, 19 Oct 2014 00:38:10 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XfeVd-0003GP-39 for pgsql-bugs@arkaria.postgresql.org; Sun, 19 Oct 2014 00:38:09 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XfeVc-0003GI-3m for pgsql-bugs@postgresql.org; Sun, 19 Oct 2014 00:38:08 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XfeVX-0000yd-Nr for pgsql-bugs@postgresql.org; Sun, 19 Oct 2014 00:38:06 +0000 MIME-Version: 1.0 Subject: BUG #11712: Empty string as error message from libpq To: pgsql-bugs@postgresql.org From: marko@joh.to Date: Sun, 19 Oct 2014 00:37:36 +0000 Message-ID: <20141019003736.2662.84048@wrigleys.postgresql.org> X-Pg-Spam-Score: -1.9 (-) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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 The following bug has been logged on the website: Bug reference: 11712 Logged by: Marko Tiikkaja Email address: marko@joh.to PostgreSQL version: 9.4beta2 Operating system: OS X Description: Hi, This has been annoying me for a while, but I never got around to reporting the bug. Reproduced on 9.1 and just tried against HEAD. Here it is in all its glory. Consider a program similar to the LISTEN/NOTIFY example here: http://www.postgresql.org/docs/9.3/static/libpq-example.html#LIBPQ-EXAMPLE-2, but with an added error handling around PQconsumeInput(): if (PQconsumeInput(conn) != 1) { fprintf(stderr, "PQconsumeInput() failed: %s\n", PQerrorMessage(conn)); PQfinish(conn); return; } Now when this program is running without SSL, and the server closes the network connection, what happens is this: PQconsumeInput() failed: i.e. the error string is empty. This happens when recv() returns 0 on EOF. pqsecure_write() says the following: "On failure, this function is responsible for putting a suitable message into conn->errorMessage", but apparently it doesn't consider recv() returning 0 a "failure", which I guess is fine. However, pqReadData() goes through all the fancy logic of determining that what happened was really an EOF, and then says the following: /* * OK, we are getting a zero read even though select() says ready. This * means the connection has been closed. Cope. Note that errorMessage * has been set already. */ But I don't see who's supposed to have been set errorMessage in that case. I think that might be true for SSL code paths, but it's certainly not true for the non-SSL ones. -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs