Skip to content

fix(worker): handle Unix-socket PGHOST in connection URL (#266)#292

Merged
affandar merged 1 commit into
mainfrom
tjgreen42/fix-pghost-socket-url
Jul 17, 2026
Merged

fix(worker): handle Unix-socket PGHOST in connection URL (#266)#292
affandar merged 1 commit into
mainfrom
tjgreen42/fix-pghost-socket-url

Conversation

@tjgreen42

@tjgreen42 tjgreen42 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Percent-encode a Unix-socket PGHOST (one starting with /) when building the worker's postgres:// connection URL so sqlx connects over the socket. TCP addresses and hostnames are unchanged.

get_host() / connect_as_user() need no change: PgConnectOptions::host() already handles socket paths.

Adds unit tests for TCP, hostname, and socket-directory inputs.

Fixes #266.

@tjgreen42
tjgreen42 force-pushed the tjgreen42/fix-pghost-socket-url branch from bfcd33c to fb98be4 Compare July 17, 2026 03:49
@tjgreen42
tjgreen42 marked this pull request as ready for review July 17, 2026 03:54
postgres_connection_string() built a postgres://user@host:port/db URL
with PGHOST as the host. A Unix-socket directory PGHOST (e.g.
CloudNativePG's /controller/run) put a raw path in the URL authority,
which the parser rejects as "empty host", so the worker never connected
and instances stayed pending.

build_connection_url() percent-encodes a socket-path host (one starting
with /) with the NON_ALPHANUMERIC set sqlx uses in its own build_url().
sqlx percent-decodes it and connects over the socket; encoding the whole
path keeps the directory opaque, so metacharacters cannot be
reinterpreted as a TCP host or query parameters. TCP addresses and
hostnames are used verbatim. get_host()/connect_as_user() already handle
socket paths via PgConnectOptions::host().

Tests cover TCP, hostname, and socket-directory inputs, including paths
with a space and URL metacharacters, asserting the URL parses to the
expected socket/host via sqlx.

Copilot-Session: b5f8cc43-8ac2-4355-90c8-18a10d488296
@tjgreen42
tjgreen42 force-pushed the tjgreen42/fix-pghost-socket-url branch from fb98be4 to bf0e81a Compare July 17, 2026 04:02
@tjgreen42
tjgreen42 marked this pull request as draft July 17, 2026 04:04
@tjgreen42
tjgreen42 marked this pull request as ready for review July 17, 2026 04:06
@tjgreen42
tjgreen42 requested review from affandar and pinodeca July 17, 2026 04:06
@affandar
affandar merged commit 768d320 into main Jul 17, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Background worker fails with "empty host" when PGHOST is a Unix socket path (CNPG/Kubernetes)

2 participants