Skip to content

pgconn: apply a 10-second connection timeout everywhere#12

Open
brmzkw wants to merge 1 commit into
mainfrom
jcastets/timeout
Open

pgconn: apply a 10-second connection timeout everywhere#12
brmzkw wants to merge 1 commit into
mainfrom
jcastets/timeout

Conversation

@brmzkw
Copy link
Copy Markdown
Collaborator

@brmzkw brmzkw commented May 8, 2026

PGCONNECT_TIMEOUT=10 is injected into every subprocess environment so that pg_dump, pg_dumpall, pg_restore, and psql all time out quickly when a packet-dropping firewall is in the way. connect_timeout=10 is added to the DSN so the same limit applies to Go-side Open/Ping calls via pgx.

The timeout is hardcoded (not configurable) and intentionally only covers the initial TCP handshake and authentication, not the duration of a running dump or restore.

PGCONNECT_TIMEOUT=10 is injected into every subprocess environment so that
pg_dump, pg_dumpall, pg_restore, and psql all time out quickly when a
packet-dropping firewall is in the way. connect_timeout=10 is added to the
DSN so the same limit applies to Go-side Open/Ping calls via pgx.

The timeout is hardcoded (not configurable) and intentionally only covers
the initial TCP handshake and authentication, not the duration of a running
dump or restore.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@brmzkw
Copy link
Copy Markdown
Collaborator Author

brmzkw commented May 8, 2026

On OSX, tested with the following:

Run a container:

docker run --rm -ti --name test -p 9999:5432 -e POSTGRES_PASSWORD=postgres postgres:17

Drop connection:

 echo "block drop out proto tcp to any port 9999" | sudo pfctl -ef -

Run a backup:

plakar -stdio at ./toto backup postgres://postgres:postgres@localhost:9999
/Users/niluje/dev/plakar/plakar/plakar: failed to backup source: rpc error: code = Unknown desc = querying server version: failed to connect to `user=postgres database=postgres`:??[::1]:9999 (localhost): tls error: write tcp [::1]:50815->[::1]:9999: write: socket is not connected??127.0.0.1:9999 (localhost): dial error: timeout: dial tcp 127.0.0.1:9999: connect: operation timed out??[::1]:9999 (localhost): failed to write startup message: write failed: write tcp [::1]:50818->[::1]:9999: write: socket is not connected??127.0.0.1:9999 (localhost): dial error: timeout: dial tcp 127.0.0.1:9999: connect: operation timed out

Revert firewall:

sudo pfctl -F rules
sudo pfctl -f /etc/pf.conf

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.

1 participant