Repository navigation
Bound the whole connection attempt by connect_timeout - #48
Merged
Merged
Conversation
Scripted servers stall after accepting, before answering SSLRequest, during the TLS and GSS handshakes, and across two stages that each answer within the timeout. Each attempt must fail with "timeout expired" within about connect_timeout. A statement run after connect_timeout has passed must still succeed, on a fresh connection and after a reconnect, and cancel_request must give up on a stalled server. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
connect_timeout bounded only the TCP connect and, with a fresh timer, the TLS handshake. A server that accepted the connection and then stalled before answering SSLRequest, startup or authentication blocked the connect, a reconnect, or cancel_query! indefinitely. Each attempt now gets one deadline, as libpq's connect_timeout does. The dial uses it, and it stays on the socket as the read and write deadline through GSS or TLS negotiation, startup, authentication and session setup. The deadline is cleared before the connection is returned, so it cannot cut off a later statement. A timeout at any stage throws Postgres.Error "timeout expired" instead of a Reseau error. cancel_request uses the same deadline. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
libpq compares sslmode and gssencmode exactly (strcmp in connectOptions2). Postgres.jl compares them case-insensitively. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merged
quinnj
referenced
this pull request
Nov 10, 2026
Co-authored-by: Jacob Quinn <quinn.jacobd@gmail.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
connect_timeoutbounded only the TCP connect, plus a fresh timer for the TLS handshake. A server that accepted the connection and then stalled blockedPostgres.Connection, areconnect=truereconnect, orcancel_query!with no limit. The server might stall before answering SSLRequest, during startup or authentication, or before ReadyForQuery. A pool checkout against an overloaded or unreachable server hung the same way. libpq'sconnect_timeoutbounds the whole attempt, and this change does the same.What changed
deadline_ns), and it stays on the socket as the read and write deadline through GSS or TLS negotiation, startup, authentication and session setup. A server that stalls at any stage fails the attempt after aboutconnect_timeoutin total. The TLS handshake no longer gets its own fresh timer._startup!), the reconnect incheckconnincluded. Otherwise it would cut off a later statement.Postgres.Error("timeout expired while connecting to host:port")instead of a ReseauOpError,TLSHandshakeTimeoutErrororTLSError.cancel_requestuses the same deadline: a dial timeout throws that error, and a stall later returnsfalse, as other cancel failures already do.check_modenow says libpq comparessslmode/gssencmodeexactly (follow-up from the Validate sslmode and gssencmode at parse time and in the constructor #47 review).Scope
gssencmode=prefer, the second dial after a failed GSS attempt shares the deadline. libpq does the same for one address.connect_timeoutof 0 or less means no limit, as in libpq. A negative value used to fail in the TLS configuration.docs/src/support.mdalready says so).API.connect.Blast Radius
The change affects every connect, reconnect and cancel that sets
connect_timeout; withoutconnect_timeoutnothing changes.OpErrororTLSHandshakeTimeoutErrornow getsPostgres.Error.connect_timeoutcan now time out.API.connectsocket(internal) now takes the attempt's deadline instead of seconds. Its keyword form, which had no callers, is removed.docs/src/support.mdsaid thatconnect_timeoutdoes not bound authentication; it now describes the new behavior.Most of the
API.connectdiff is reindentation from the new outertry. Review it with whitespace ignored.Verification
connect_timeout=1. On main (3d8ba83), silent after accept, an unanswered SSLRequest, andcancel_requestwere all still waiting after 8 s. A stalled TLS handshake threw Reseau'sTLSHandshakeTimeoutErrorafter 1.11 s. Two stages of 0.6 s each connected after 1.37 s. A dial to 10.255.255.1 threw a ReseauOpErrorafter 1.16 s. With this PR, every case throwsPostgres.Error"timeout expired" after 1.04 to 1.10 s,cancel_requestreturnsfalseafter 1.05 s, and a statement run 1.5 s after connecting succeeds.connect_timeout=1against postgres:16 with SCRAM: the first connection succeeds, so first-call compilation does not eat the window.test/connect_timeout_fake_server.jl, plus a stalled GSS handshake intest/gssapi.jl). FullPkg.test()on Julia 1.12.6 (macOS arm64) with the Docker integration (postgres:16) and the trim compile test: 9949/9949, which is main's 9919 plus the 30 new checks.🤖 Generated with Claude Code