pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: marko@joh.to
To: pgsql-bugs@postgresql.org
Subject: BUG #11712: Empty string as error message from libpq
Date: Sun, 19 Oct 2014 00:37:36 +0000
Message-ID: <20141019003736.2662.84048@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

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



view thread (2+ messages)  latest in thread

Message-ID: <20141019003736.2662.84048@wrigleys.postgresql.org>
Permalink:  ../20141019003736.2662.84048@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/20141019003736.2662.84048@wrigleys.postgresql.org

 · 

reply

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: marko@joh.to
  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>

* 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