Thread: [GENERAL] libpq: PQreset not reconnecting connection, even though server is running

Hi

I have code in our "run this query" shim that automatically attempts
to reconnect to the server if it finds that the connection is bad
(usually it's just there to handle unexpected postmaster restarts).

   while (PQstatus(Conn) == CONNECTION_BAD) {     fprintf(stderr, "postgres connection status is CONNECTION_BAD:
attempting to reconnect\n");     PQreset(Conn);     if (PQstatus(Conn) == CONNECTION_BAD) {       usleep(1000000);
}  }
 

Yesterday, we found that one (just-created) thread had got stuck in
this loop, even though all other processes were still talking to the
server with no problems.

Around the time of the first failure we got a message about
"incomplete startup packet" in the postgres log.

I'm guessing (from "incomplete startup packet") that the connection
created by the new thread never actually succeeded, is that the
problem? Will PQreset only work on a connection that had previously
connected successfully?

If that _is_ the case, is there a way to tell up-front whether this is
the case (so I can retry PQconnectdb instead of calling PQreset)?

Thanks

Geoff


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

I wrote:
> I'm guessing (from "incomplete startup packet") that the connection
> created by the new thread never actually succeeded, is that the
> problem? Will PQreset only work on a connection that had previously
> connected successfully?

And as soon as I hit "send" on this email light dawned: the code that
calls our "creates db connection" function is not checking the return
value correctly, and PQreset fails because our that function wipes out
the connection object (assuming that it cannot be used).

Sorry to waste bandwidth.

Geoff


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