pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #11455: PQerrorMessage not reset after PQreset
5+ messages / 4 participants
[nested] [flat]

* BUG #11455: PQerrorMessage not reset after PQreset
@ 2014-09-19 16:57  postgresql-bklyn@sneakemail.com
  0 siblings, 1 reply; 5+ messages in thread

From: postgresql-bklyn@sneakemail.com @ 2014-09-19 16:57 UTC (permalink / raw)
  To: pgsql-bugs

The following bug has been logged on the website:

Bug reference:      11455
Logged by:          Caleb Epstein
Email address:      postgresql-bklyn@sneakemail.com
PostgreSQL version: 9.3.4
Operating system:   Linux
Description:        

I'm testing application logic to reconnect to my database server after a
connection failure.  I'm using PQreset() and I notice that the
PQerrorMessage() result keeps growing after each failed reconnect.

For example, see belwo.  My application log messages start with "Database". 
The "... Resetting" message is followed by a call to PQreset().  The "FATAL"
messages are the strings returned to be by PQerrorMessage.

Database connection failed.  Resetting.
Database reconnect failed: FATAL:  terminating connection due to
administrator command
FATAL:  terminating connection due to administrator command 
FATAL:  the database system is shutting down
Database connection unavailable.  Cannot persist
Database connection failed.  Resetting.
Database reconnect failed: FATAL:  terminating connection due to
administrator command
FATAL:  terminating connection due to administrator command 
FATAL:  the database system is shutting down
FATAL:  the database system is shutting down

The next error will have 3 instances of "system is shutting down", and so
on.

Thanks!



-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: BUG #11455: PQerrorMessage not reset after PQreset
@ 2014-09-19 19:57  Tom Lane <tgl@sss.pgh.pa.us>
  parent: postgresql-bklyn@sneakemail.com
  0 siblings, 2 replies; 5+ messages in thread

From: Tom Lane @ 2014-09-19 19:57 UTC (permalink / raw)
  To: postgresql-bklyn@sneakemail.com; +Cc: pgsql-bugs

postgresql-bklyn@sneakemail.com writes:
> I'm testing application logic to reconnect to my database server after a
> connection failure.  I'm using PQreset() and I notice that the
> PQerrorMessage() result keeps growing after each failed reconnect.

It's unlikely that anyone is going to look into this unless you provide
a self-contained test case (ie, a small program that reproduces the
misbehavior).  It's too hard to guess exactly what you did.

			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



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: BUG #11455: PQerrorMessage not reset after PQreset
@ 2014-09-19 20:47  Caleb Epstein <cae@bklyn.org>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  1 sibling, 0 replies; 5+ messages in thread

From: Caleb Epstein @ 2014-09-19 20:47 UTC (permalink / raw)
  To: Tom Lane tgl-at-sss.pgh.pa.us |postgresql-bklyn| <uabn4z8tjt@sneakemail.com>; +Cc: postgresql-bklyn@sneakemail.com; pgsql-bugs

Test program (C++0x) attached.  Run it with a connection info string as
argv[1].  It should print a dot once per second while the DB connection is
OK, but will print the PQerrorMessage text when the connection fails, and
then will PQreset the connection.  Each time it prints the error you can
see all the previous error content and the error buffer just keeps growing
and growing rather than resetting when PQreset is called.

If instead of calling "PQreset", one calls "PQfinish" and "PQconnectdb"
(e.g. change the call from "reset" to "reconnect" on line 39), you'll
(naturally) see just the most recent error.

On Fri, Sep 19, 2014 at 3:57 PM, Tom Lane tgl-at-sss.pgh.pa.us
|postgresql-bklyn| <uabn4z8tjt@sneakemail.com> wrote:

> postgresql-bklyn@sneakemail.com writes:
> > I'm testing application logic to reconnect to my database server after a
> > connection failure.  I'm using PQreset() and I notice that the
> > PQerrorMessage() result keeps growing after each failed reconnect.
>
> It's unlikely that anyone is going to look into this unless you provide
> a self-contained test case (ie, a small program that reproduces the
> misbehavior).  It's too hard to guess exactly what you did.
>
>                         regards, tom lane
>



-- 
Caleb Epstein

-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Attachments:

libpq-error-cascade.cpp (text/x-c++src, 1.2K) download #include <postgresql/libpq-fe.h> #include <unistd.h> #include <iostream> using namespace std; const char* connInfo = nullptr; bool reconnect (PGconn*& dbh) { if (dbh) PQfinish (dbh); dbh = PQconnectdb (connInfo); return PQstatus (dbh) == CONNECTION_OK; } bool reset (PGconn*& dbh) { PQreset (dbh); return PQstatus (dbh) == CONNECTION_OK; } int main (int argc, char** argv) { if (argc < 2) { cerr << "Usage: " << argv[0] << " CONN-INFO" << endl; exit (1); } connInfo = argv[1]; int status = 1; PGconn* dbh = nullptr; reconnect (dbh); while (true) { if (PQstatus (dbh) != CONNECTION_OK) { cerr << "Error @" << (void*) PQerrorMessage (dbh) << ": " << PQerrorMessage (dbh); reset (dbh); } else { auto* res = PQexec (dbh, "select now()"); if (PQresultStatus (res) != PGRES_TUPLES_OK) { cerr << "Query error: " << PQresultErrorMessage (res); } else { cout << '.' << flush; } if (res) PQclear (res); } sleep (1); } if (dbh) PQfinish (dbh); exit (status); }
^ permalink raw reply [nested|flat] 5+ messages in thread

* Re: BUG #11455: PQerrorMessage not reset after PQreset
@ 2014-09-19 21:12  Caleb Epstein <cae@bklyn.org>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  1 sibling, 1 reply; 5+ messages in thread

From: Caleb Epstein @ 2014-09-19 21:12 UTC (permalink / raw)
  To: Tom Lane tgl-at-sss.pgh.pa.us |postgresql-bklyn| <uabn4z8tjt@sneakemail.com>; +Cc: postgresql-bklyn@sneakemail.com; pgsql-bugs

Here is the same logic in plain old C incase compiling or running C++0x
code is problematic for anyone.

On Fri, Sep 19, 2014 at 3:57 PM, Tom Lane tgl-at-sss.pgh.pa.us
|postgresql-bklyn| <uabn4z8tjt@sneakemail.com> wrote:

> postgresql-bklyn@sneakemail.com writes:
> > I'm testing application logic to reconnect to my database server after a
> > connection failure.  I'm using PQreset() and I notice that the
> > PQerrorMessage() result keeps growing after each failed reconnect.
>
> It's unlikely that anyone is going to look into this unless you provide
> a self-contained test case (ie, a small program that reproduces the
> misbehavior).  It's too hard to guess exactly what you did.
>
>                         regards, tom lane
>



-- 
Caleb Epstein

-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Attachments:

libpq-error.c (text/x-csrc, 1.2K) download #include <postgresql/libpq-fe.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> void reconnect (PGconn** dbh, const char* connInfo) { if (*dbh) PQfinish (*dbh); *dbh = PQconnectdb (connInfo); } void reset (PGconn** dbh, const char* connInfo) { PQreset (*dbh); } int main (int argc, char** argv) { if (argc < 2) { fprintf (stderr, "Usage: %s CONN-INFO\n", argv[0]); exit (1); } const char* connInfo = argv[1]; PGconn* dbh = 0; reconnect (&dbh, connInfo); while (1) { if (PQstatus (dbh) != CONNECTION_OK) { fprintf (stderr, "Error: %s\n", PQerrorMessage (dbh)); /* Change this to "reconnect" and you get only the most * recent error, not an ever-growing cascade */ reset (&dbh, connInfo); } else { PGresult* res = PQexec (dbh, "select now()"); if (PQresultStatus (res) != PGRES_TUPLES_OK) { fprintf (stderr, "Query error: %s\n", PQresultErrorMessage (res)); } else { putc ('.', stdout); fflush (stdout); } if (res) PQclear (res); } sleep (1); } if (dbh) PQfinish (dbh); exit (0); }
^ permalink raw reply [nested|flat] 5+ messages in thread

* Re: BUG #11455: PQerrorMessage not reset after PQreset
@ 2014-10-29 12:45  Heikki Linnakangas <hlinnakangas@vmware.com>
  parent: Caleb Epstein <cae@bklyn.org>
  0 siblings, 0 replies; 5+ messages in thread

From: Heikki Linnakangas @ 2014-10-29 12:45 UTC (permalink / raw)
  To: Caleb Epstein <cae@bklyn.org>; +Cc: postgresql-bklyn@sneakemail.com; pgsql-bugs

On 09/20/2014 12:12 AM, Caleb Epstein wrote:
> Here is the same logic in plain old C incase compiling or running C++0x
> code is problematic for anyone.

Fixed, thanks for the report and test case!

- Heikki



-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2014-10-29 12:45 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2014-09-19 16:57 BUG #11455: PQerrorMessage not reset after PQreset postgresql-bklyn@sneakemail.com
2014-09-19 19:57 ` Tom Lane <tgl@sss.pgh.pa.us>
2014-09-19 20:47   ` Caleb Epstein <cae@bklyn.org>
2014-09-19 21:12   ` Caleb Epstein <cae@bklyn.org>
2014-10-29 12:45     ` Heikki Linnakangas <hlinnakangas@vmware.com>

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