Skip to content

Commit 49cd8a3

Browse files
committed
On further testing, PQping also needs an explicit check for AUTH_REQ.
The pg_fe_sendauth code might fail if it can't handle the authentication request message type --- if so, ping should still say the server is up.
1 parent db96e1c commit 49cd8a3

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/interfaces/libpq/fe-connect.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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. */
23252327
if (pqGetInt((int *) &areq, 4, conn))
23262328
{
@@ -2589,11 +2591,18 @@ internal_ping(PGconn *conn)
25892591
return PQPING_OK;
25902592

25912593
/*
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
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)
26722681
conn->std_strings = false; /* unless server says differently */
26732682
conn->verbosity = PQERRORS_DEFAULT;
26742683
conn->sock = -1;
2684+
conn->auth_req_received = false;
26752685
conn->password_needed = false;
26762686
conn->dot_pgpass_used = false;
26772687
#ifdef USE_SSL

src/interfaces/libpq/libpq-int.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ struct pg_conn
349349
SockAddr raddr; /* Remote address */
350350
ProtocolVersion pversion; /* FE/BE protocol version in use */
351351
int sversion; /* server version, e.g. 70401 for 7.4.1 */
352+
bool auth_req_received; /* true if any type of auth req received */
352353
bool password_needed; /* true if server demanded a password */
353354
bool dot_pgpass_used; /* true if used .pgpass */
354355
bool sigpipe_so; /* have we masked SIGPIPE via SO_NOSIGPIPE? */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy