Skip to content
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

Validate all addresses resolved from hostname #14

Merged
merged 4 commits into from
Sep 20, 2019

Conversation

furdarius
Copy link
Contributor

@furdarius furdarius commented Sep 13, 2019

LookupFunc added to config, so custom resolver can be used.

fallbackConfigs used to iterate over resolved addrs.

fix: #5

Signed-off-by: Artemiy Ryabinkov <getlag@ya.ru>
Signed-off-by: Artemiy Ryabinkov <getlag@ya.ru>
Signed-off-by: Artemiy Ryabinkov <getlag@ya.ru>
@furdarius
Copy link
Contributor Author

@jackc what do you think about this PR?

@jackc
Copy link
Owner

jackc commented Sep 20, 2019

Sorry, somehow I unwatched my own project so I didn't see this until you pinged me...

This PR is actually combining two concerns.

  1. Allowing a custom resolver
  2. Expanding a host name into multiple addresses

There are some subtle edge cases with each.

The custom resolver appears to only be called by expandWithIPs and that appends to the fallbacks. That means that the host name will be dialed with the default resolver before the custom resolver is tried. Presumably that is not desired.

The other issue is what happens when DNS changes. A Config could be used for a long time in a server process. and it could be stuck never seeing the updated DNS.

For both concerns to work properly, the DNS resolution (and expansion to multiple IPs) has to occur at dial time not parse config time.

@furdarius
Copy link
Contributor Author

Hm, any kind of resolving and dealing occurs only inside ConnectConfig func.
So, while the connection, received from ConnectConfig, is alive - we don't care about DNS changes, cuz we just use this connection to work with DB.

But, in case of connection is broken we apparently try to reconnect, so we call ConnectConfig again - this leads to new DNS resolving (if DNS records was updated - we will receive valid addrs).

The custom resolver appears to only be called by expandWithIPs and that appends to the fallbacks. That means that the hostname will be dialed with the default resolver before the custom resolver is tried.

I don't see any calls of DialFunc before expandWithIPs. A single call of DialFunc is inside connect (https://github.com/furdarius/pgconn/blob/resolve-hostnames-into-addrs/pgconn.go#L201) and it occurs only after hostnames resolved.

Maybe I got you wrong.

@jackc jackc merged commit 3f377ac into jackc:master Sep 20, 2019
@jackc
Copy link
Owner

jackc commented Sep 20, 2019

Wow... I really shouldn't review PRs when I'm tired... For some reason I thought the changes to ConnectConfig were in ParseConfig and thought that expandWithIPs was appending to the existing fallbacks instead of creating a whole new list. Now that I'm looking at it again I see I was wrong on both accounts.

LGTM.

horgh added a commit to horgh/pgconn that referenced this pull request Feb 16, 2022
With `expandWithIPs()` (added in jackc#14), we try all IPs.
jackc pushed a commit that referenced this pull request Feb 19, 2022
With `expandWithIPs()` (added in #14), we try all IPs.
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.

Try all IP addresses resolved from a host name
2 participants