Skip to content

Commit 642775c

Browse files
sfc-gh-rbachalasfc-gh-mslot
authored andcommitted
pgduck client: unsetenv PGHOSTADDR before connecting
PGHOSTADDR overrides host= in the conninfo even when an explicit unix-socket path is set, silently redirecting libpq to connect via TCP instead. Clear it before PQconnectdb so the configured conninfo is always honoured. Stacks on #361, which adds ResolvePgduckConninfo() diagnostic logging for the same issue class. Together the two changes prevent the override and make any remaining connection failures self-diagnosing. Fixes #293. Signed-off-by: Richie Bachala <richie.bachala@snowflake.com>
1 parent bba35ff commit 642775c

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

pg_lake_engine/src/pgduck/client.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,11 @@ SetupPgDuckConnectionHash(void)
131131
/*
132132
* ResolvePgduckConninfo returns a palloc'd connection string showing the
133133
* options libpq would actually use to reach pgduck_server, including values
134-
* supplied via environment variables (e.g. PGHOSTADDR, PGPORT) and libpq's
134+
* supplied via environment variables (e.g. PGPORT, PGUSER) and libpq's
135135
* compiled-in defaults. This is what an administrator needs to debug a
136136
* misconfigured server -- PgduckServerConninfo alone hides any env-supplied
137-
* overrides.
137+
* overrides. Note: PGHOSTADDR is cleared before connecting (see caller),
138+
* so it will not appear in the resolved output.
138139
*
139140
* We resolve options without opening a socket: PQconndefaults() returns the
140141
* options with environment variables and compiled-in defaults applied, and
@@ -205,9 +206,18 @@ ResolvePgduckConninfo(void)
205206
PGDuckConnection *
206207
GetPGDuckConnection(void)
207208
{
208-
InitializePGDuckClient();
209-
210-
PGconn *connection = PQconnectdb(PgduckServerConninfo);
209+
InitializePGDuckClient();
210+
211+
/*
212+
* PGHOSTADDR, if set in the server environment, overrides host= in the
213+
* conninfo — including unix-socket paths — and silently redirects libpq
214+
* to connect via TCP to a numeric IP instead. Clear it before connecting
215+
* so PgduckServerConninfo is always honoured. Unlike PGHOST/PGPORT, which
216+
* lose to explicit conninfo values, PGHOSTADDR unconditionally wins.
217+
*/
218+
unsetenv("PGHOSTADDR");
219+
220+
PGconn *connection = PQconnectdb(PgduckServerConninfo);
211221

212222
if (PQstatus(connection) != CONNECTION_OK)
213223
{

0 commit comments

Comments
 (0)