@@ -2321,6 +2321,8 @@ PQconnectPoll(PGconn *conn)
23212321}
23222322
23232323/* It is an authentication request. */
2324+ conn -> auth_req_received = true;
2325+
23242326/* Get the type of request. */
23252327if (pqGetInt ((int * )& areq ,4 ,conn ))
23262328{
@@ -2589,11 +2591,18 @@ internal_ping(PGconn *conn)
25892591return PQPING_OK ;
25902592
25912593/*
2592- * Hereis the interesting part of "ping": determine the cause of the
2594+ * Herebegins the interesting part of "ping": determine the cause of the
25932595 * failure in sufficient detail to decide what to return. We do not want
25942596 * to report that the server is not up just because we didn't have a valid
2595- * password, for example.
2596- *
2597+ * password, for example. In fact, any sort of authentication request
2598+ * implies the server is up. (We need this check since the libpq side
2599+ * of things might have pulled the plug on the connection before getting
2600+ * an error as such from the postmaster.)
2601+ */
2602+ if (conn -> auth_req_received )
2603+ return PQPING_OK ;
2604+
2605+ /*
25972606 * If we failed to get any ERROR response from the postmaster, report
25982607 * PQPING_NO_RESPONSE. This result could be somewhat misleading for a
25992608 * pre-7.4 server, since it won't send back a SQLSTATE, but those are long
@@ -2672,6 +2681,7 @@ makeEmptyPGconn(void)
26722681conn -> std_strings = false;/* unless server says differently */
26732682conn -> verbosity = PQERRORS_DEFAULT ;
26742683conn -> sock = -1 ;
2684+ conn -> auth_req_received = false;
26752685conn -> password_needed = false;
26762686conn -> dot_pgpass_used = false;
26772687#ifdef USE_SSL