-
Notifications
You must be signed in to change notification settings - Fork 888
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong host in ConnectError #1929
Comments
As of Go 1.20 we now have a better way of returning multiple errors. That's a reasonable change. 👍 |
A single Connect("connstring") may actually make multiple connection requests due to TLS or HA configuration. Previously, when all attempts failed only the last error was returned. This could be confusing. Now details of all failed attempts are included. For example, the following connection string: host=localhost,127.0.0.1,foo.invalid port=1,2,3 Will now return an error like the following: failed to connect to `user=postgres database=pgx_test`: lookup foo.invalid: no such host [::1]:1 (localhost): dial error: dial tcp [::1]:1: connect: connection refused 127.0.0.1:1 (localhost): dial error: dial tcp 127.0.0.1:1: connect: connection refused 127.0.0.1:2 (127.0.0.1): dial error: dial tcp 127.0.0.1:2: connect: connection refused #1929
I've added multiple error returns for connection failures in 8db9716. For example, the following connection string:
Will now return an error like the following:
|
Describe the bug
When a connection string contains multiple hosts, the
Config.Host
field is populated with the first host, while the remaining hosts are treated asFallbackConfig
s. Theconnect
function, which accepts bothConfig
andFallbackConfig
to establish a connection, uses theHost
andPort
from the FallbackConfig.pgx/pgconn/pgconn.go
Line 283 in da6f2c9
However, in the event of a connection error, the default
Config
is used, leading to a mismatch between the error message (which contains the IP address of the host we attempted to connect to) and theHost
andPort
from a different host.pgx/pgconn/pgconn.go
Line 286 in da6f2c9
To Reproduce
Steps to reproduce the behavior:
Expected behavior
The error message should match the host we attempted to connect to. Possible outcome are
host=localhost ... dial tcp 127.0.0.1:1234
host=127.0.0.1 ... dial tcp 127.0.0.1:5678
Actual behavior
The error message contains a mismatched host and port
Additional context
It would be more informative to return an error group containing connection errors for all attempted hosts. This would be particularly useful when
target_session_attrs=primary
is used and a connection to the primary cannot be established. In this case we can get a uselessserver is in standby mode
while connecting to the other node.The text was updated successfully, but these errors were encountered: