sequelize: ETIMEDOUT exception brings down connection to database
I’m using Sequelize 3.1.0 (haven’t had time to update to 3.2.0 yet) with node 0.12.4 and I’m having pretty severe issues around communicating with Postgresql.
The problem is that I get an ETIMEDOUT exception, which seems to crash Sequelize. I get this exception 5 times on an app which uses a connection pool that can have a maximum of 5 connections, so I’m thinking that this happens once per connection, even more so because these 5 errors also occur at the same time. Here’s the log:
[debug] 2015-06-06 20:46:18 'Executing (default): INSERT INTO "FooBar" ("id","url","FooId","BarId","updatedAt","createdAt") VALUES (DEFAULT,\'http://www.example.com/my/example/path\',466,1,\'2015-06-06 18:30:30.701 +00:00\',\'2015-06-06 18:30:30.701 +00:00\') RETURNING *;'
Unhandled rejection SequelizeDatabaseError: read ETIMEDOUT
at Query.formatError (/home/manifact/recorded-web/interface/node_modules/rw-scraper/node_modules/rw-data-model/node_modules/sequelize/lib/dialects/postgres/query.js:420:14)
at null.<anonymous> (/home/manifact/recorded-web/interface/node_modules/rw-scraper/node_modules/rw-data-model/node_modules/sequelize/lib/dialects/postgres/query.js:104:19)
at emit (events.js:107:17)
at Query.handleError (/home/manifact/recorded-web/interface/node_modules/rw-scraper/node_modules/rw-data-model/node_modules/pg/lib/query.js:99:8)
at null.<anonymous> (/home/manifact/recorded-web/interface/node_modules/rw-scraper/node_modules/rw-data-model/node_modules/pg/lib/client.js:166:26)
at emit (events.js:107:17)
at Socket.<anonymous> (/home/manifact/recorded-web/interface/node_modules/rw-scraper/node_modules/rw-data-model/node_modules/pg/lib/connection.js:59:10)
at Socket.emit (events.js:107:17)
at net.js:459:14
at process._tickCallback (node.js:355:11)
After the error, Sequelize stops logging, but no exceptions are thrown when trying to save data.
I’ve tried finding out some details about the ETIMEDOUT error, but there wasn’t much to go on. Here’s an example of a ticket in node-mysql
that looks similar to this one, though https://github.com/felixge/node-mysql/issues/904
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 44 (7 by maintainers)
We’ve struggled with this issue for quite long, but worked around with the below at the end:
I get this error also. I tried to set the min: 1 and idle: 30000 (30 seconds) in the pool settings but it didn’t solve my issue.
@jared-evari You need to update your inbound connections. Go to the databases list in your AWS Console, select the database that you need to update, then do a search on the page for ‘VPC security groups’ (it’s under the ‘Security’ label). You will see the link for the security group under the ‘VPC security groups’. Open that link. In the bottom of the page, select ‘Inbound’ tab. Press ‘Edit’, then ‘Add Rule’. Enter the following values: Type: Custom TCP, Protocol: TCP, Port Range: 0, Source: Custom, IP addresses field: 0.0.0.0/0, ::/0, Description: you can leave this empty. Press ‘Save’.
As @rsshilli said, something was blocking the connection, in my case, i had to allow inbound connections from heroku ip to my rds database in AWS. Also, im not sure if setting DATABASE_URL in Heroku config variable helped
If any of you are seeing this error consistently, you have a firewall problem. I guarantee it. Something, somewhere is stopping the connection. It mostly likely isn’t your Sequelize settings.
With that said, we see this error very rarely, but maybe once every 500 times an AWS Lambda starts up. It only happens when the Lambda is fresh (ie. hasn’t been run in over 20 mins) and needs to make an initial connection. Once the Lambda has started it’ll re-use the old connection and this problem will never happen.
We’re running on Sequelize 3.30.4, Node 6.10.3 and MySQL ^2.13.0. My connection pool settings look like this:
What’s even stranger, is that I have other Lambdas that share the exact same startup code (I mean exactly the same zip, different method) that startup a second or two before I see this error and they run fine. They’re all connecting to the same RDS database, which shows about 5 DB connections at the time (not high at all) nor a high load on the DB. It’s very strange.
Here’s the full stack trace:
I suspect there’s something wrong at the connection pool level, but I’m not sure how to diagnose this further. Any ideas?
For people experiencing issues in AWS Lambda, I have created a pull request that documents how to properly configure
sequelize
for Lambda. Hopefully you’ll be able to see it in https://sequelize.org/master/manual/aws-lambda.html once it gets merged. In the meantime, please check #12642 out and provide feedback if you find any inaccuracies or space for improvement.In addition to @sharq88 's options above, this one helps too:
Here’s the link to the SO page, so you don’t have to copy & paste: https://stackoverflow.com/a/52465919/491553
+1
My situation was like what @dts-peter said, but with Google Cloud SQL.
same error, on aws ec2. anyone can help?
You can fiddle around here https://github.com/sequelize/sequelize/blob/master/lib/dialects/postgres/connection-manager.js and here: https://github.com/sequelize/sequelize/blob/master/lib/dialects/abstract/connection-manager.js
Specifically you might want to tjek if
$destroy
is ever called: https://github.com/sequelize/sequelize/blob/master/lib/dialects/abstract/connection-manager.js#L79