Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Xh4CV-00077H-AJ for pgsql-bugs@arkaria.postgresql.org; Wed, 22 Oct 2014 22:16:15 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Xh4CT-0008HQ-Ut for pgsql-bugs@arkaria.postgresql.org; Wed, 22 Oct 2014 22:16:13 +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 1Xh4CT-0008HJ-1b for pgsql-bugs@postgresql.org; Wed, 22 Oct 2014 22:16:13 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Xh4CK-0002YU-LD for pgsql-bugs@postgresql.org; Wed, 22 Oct 2014 22:16:12 +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 s9MMG1E7031204; Wed, 22 Oct 2014 18:16:01 -0400 From: Tom Lane To: marko@joh.to cc: pgsql-bugs@postgresql.org Subject: Re: BUG #11712: Empty string as error message from libpq In-reply-to: <20141019003736.2662.84048@wrigleys.postgresql.org> References: <20141019003736.2662.84048@wrigleys.postgresql.org> Comments: In-reply-to marko@joh.to message dated "Sun, 19 Oct 2014 00:37:36 -0000" Date: Wed, 22 Oct 2014 18:16:01 -0400 Message-ID: <31203.1414016161@sss.pgh.pa.us> X-Pg-Spam-Score: -3.3 (---) 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 marko@joh.to writes: > 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. Hmm. I wonder why we're not getting ECONNRESET, since surely the TCP stack knows the other end is dead? Anyway, it looks to me like the best fix is just to set an error message, ie copy this bit printfPQExpBuffer(&conn->errorMessage, libpq_gettext( "server closed the connection unexpectedly\n" "\tThis probably means the server terminated abnormally\n" "\tbefore or while processing the request.\n")); right before definitelyFailed:. For the goto's leading to that label, it's reasonable to expect that lower-level code set the errorMessage, but this will not have happened when pqsecure_read returns zero, since the whole point is that it doesn't know there's anything wrong. 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