@@ -2321,6 +2321,8 @@ PQconnectPoll(PGconn *conn)
2321
2321
}
2322
2322
2323
2323
/* It is an authentication request. */
2324
+ conn -> auth_req_received = true;
2325
+
2324
2326
/* Get the type of request. */
2325
2327
if (pqGetInt ((int * ) & areq , 4 , conn ))
2326
2328
{
@@ -2589,11 +2591,18 @@ internal_ping(PGconn *conn)
2589
2591
return PQPING_OK ;
2590
2592
2591
2593
/*
2592
- * Here is the interesting part of "ping": determine the cause of the
2594
+ * Here begins the interesting part of "ping": determine the cause of the
2593
2595
* failure in sufficient detail to decide what to return. We do not want
2594
2596
* 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
+ /*
2597
2606
* If we failed to get any ERROR response from the postmaster, report
2598
2607
* PQPING_NO_RESPONSE. This result could be somewhat misleading for a
2599
2608
* pre-7.4 server, since it won't send back a SQLSTATE, but those are long
@@ -2672,6 +2681,7 @@ makeEmptyPGconn(void)
2672
2681
conn -> std_strings = false; /* unless server says differently */
2673
2682
conn -> verbosity = PQERRORS_DEFAULT ;
2674
2683
conn -> sock = -1 ;
2684
+ conn -> auth_req_received = false;
2675
2685
conn -> password_needed = false;
2676
2686
conn -> dot_pgpass_used = false;
2677
2687
#ifdef USE_SSL
0 commit comments