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

Using hostaddr will cache the DNS lookup #2740

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mjgp2
Copy link

@mjgp2 mjgp2 commented May 3, 2022

This fixes occurrences where the IP changes for a native connection, e.g. with read replicas.

"If host is specified without hostaddr, a host name lookup occurs."

https://www.postgresql.org/docs/8.1/libpq.html#LIBPQ-CONNECT

You do not need to do the DNS lookup in javascript.

Fixes: #1748

@mjgp2 mjgp2 force-pushed the native-client-dns-caching-fix branch from 4f4c27a to 2a82c1c Compare May 3, 2022 17:51
@charmander
Copy link
Collaborator

You do not need to do the DNS lookup in javascript.

The reason it’s done in JavaScript is that it’s blocking in libpq, IIRC.

@mjgp2
Copy link
Author

mjgp2 commented May 4, 2022

It is blocking at within libpq (uses getaddrinfo), but it's seemingly done on a separate thread from the comment in the code, so should not block the node event loop?

https://github.com/brianc/node-libpq/blob/master/index.js#L34

FWIW we are experiencing a stale hostaddr in the connection string causing downtime on services.

@brianc
Copy link
Owner

brianc commented May 11, 2022

Yah looking at this....I think the dns lookup in JS was done before I rewrote libpq bindings and made a proper background async connection worker thread. So this isn't needed now that we're running libpq's connect in node's threadpool.

Hey sorry for the headache here but CI was broken. I fixed it yesterday...would you be able to rebase onto master? Then the tests should pass and we can merge this up and get a release out! Thank you so much for contributing! ❤️

@mjgp2 mjgp2 force-pushed the native-client-dns-caching-fix branch from 2a82c1c to aa8774a Compare May 11, 2022 18:41
@mjgp2
Copy link
Author

mjgp2 commented May 11, 2022

Rebased!

Thanks so much for all your hard work, I totally <3 this library :)

@mjgp2
Copy link
Author

mjgp2 commented May 11, 2022

@brianc - is the CI still broken, doesn't look like a test failure.

@brianc
Copy link
Owner

brianc commented May 12, 2022

I'll try rerunning it - very weird error there I didn't on my branches or on master

@brianc
Copy link
Owner

brianc commented May 12, 2022

It looks like the errors in CI might be related to this PR...the other PR's I've rebased have all passed CI okay. 😢

"If host is specified without hostaddr, a host name lookup occurs."

https://www.postgresql.org/docs/8.1/libpq.html#LIBPQ-CONNECT
@mjgp2 mjgp2 force-pushed the native-client-dns-caching-fix branch from aa8774a to 51bf508 Compare October 24, 2022 08:59
@mjgp2
Copy link
Author

mjgp2 commented Oct 24, 2022

@brianc - I rebased, can you try rerunning?

@mjgp2
Copy link
Author

mjgp2 commented Oct 24, 2022

Also, can you point me towards the settings for running unit tests against the local pg instance

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.

Exception For database connection Timeout. Store IP of Database in cache
3 participants