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

Exception For database connection Timeout. Store IP of Database in cache #1748

Open
RaviDavda opened this issue Oct 12, 2018 · 3 comments · May be fixed by #2740
Open

Exception For database connection Timeout. Store IP of Database in cache #1748

RaviDavda opened this issue Oct 12, 2018 · 3 comments · May be fixed by #2740

Comments

@RaviDavda
Copy link

RaviDavda commented Oct 12, 2018

When We have created database connection through connection string, it might store ip in the cache in your library and for next every connection it uses that IP. Now my database configuration changed but host, username, password is same and private ip of database changed. Now pg library try to connect on old IP and we are having new IP. So my every API gets failed.
{ "message": "error: terminating connection due to administrator command at Connection.parseE (/usr/src/app/node_modules/pg/lib/connection.js:545:11) at Connection.parseMessage (/usr/src/app/node_modules/pg/lib/connection.js:370:19) at Socket.<anonymous> (/usr/src/app/node_modules/pg/lib/connection.js:113:22) at emitOne (events.js:116:13) at Socket.emit (events.js:211:7) at addChunk (_stream_readable.js:263:12) at readableAddChunk (_stream_readable.js:250:11) at Socket.Readable.push (_stream_readable.js:208:10) at TCP.onread (net.js:597:20)", "timestamp": "2018-10-09T04:56:00.329Z", "type": "err", "process_id": 0, "app_name": "api-server" }

{ "message": "Error: connect ECONNREFUSED 11.0.3.5:5432 at Object._errnoException (util.js:992:11) at _exceptionWithHostPort (util.js:1014:20) at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1186:14)", "timestamp": "2018-10-09T04:56:02.963Z", "type": "err", "process_id": 0, "app_name": "api-server" }

Here IP and PORT number is fake, but same error I was getting since last 3 days.

So I want to know the possible solution for this.

@sehrope
Copy link
Contributor

sehrope commented Oct 12, 2018

This is not caused by the driver. It doesn't perform any DNS caching. Your operating system / network stack is probably doing it though.

Check the DNS records for your database to see what the TTL (Time To Live) value. That's how many seconds the value can be cached. The default for your DNS provider is probably something large like 3600 (1 hour) or 7200 (2 hours). A smaller value like 60 (1-minute) would lower the failover time.

@zaggino
Copy link

zaggino commented Feb 17, 2019

I ran into similar issue. Our DB is hosted by Amazon's RDS and we connect to it by hostname, when RDS goes through upgrade our apps immediately go to ECONNREFUSED mode. I though it to be an IP change behind the hostname so I started making notes of IP before an update, IP after an update and then I realized that the IP doesn't change. Anything else is cached by the library which might be causing this? Restarting the node app makes it connect immediately without problems until next Postgres update.

@sysrun
Copy link

sysrun commented Jul 8, 2019

I think the "problem" ist this:

dns.lookup(this.host, function (err, address) {

It's only called once upon initialisation

@mjgp2 mjgp2 linked a pull request May 3, 2022 that will close this issue
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 a pull request may close this issue.

4 participants