You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Testing the connection to a postgres amazon rds instance
constsequelize=newSequelize('dbname','username','password',{host: 'example.rds.amazonaws.com',dialect: 'postgres'});sequelize.authenticate().then(()=>{console.log('Connection has been established successfully.');}).catch(err=>{console.error('Unable to connect to the database:',err);});
What do you expect to happen?
App should connect and should output in console: "Connection has been established successfully"
What is actually happening?
Unable to connect to the database: { TimeoutError: ResourceRequest timed out
at ResourceRequest._fireTimeout (\myapp\node_modules\generic-pool\lib\ResourceRequest.js:58:17)
at Timeout.bound (\myapp\node_modules\generic-pool\lib\ResourceRequest.js:8:15)
at ontimeout (timers.js:380:14)
at tryOnTimeout (timers.js:244:5)
at Timer.listOnTimeout (timers.js:214:5) name: 'TimeoutError' }
Reacted by Eduard Kozachok, Piotr Gąsiorowski, Achille Njomo, CHOIX, Bart Wu, Tasos Boulis, Widada, Nick Olinger, Kyle, Volodymyr Sevastianov and 5 more
Tried the same endpoint and other credentials using pg-promise, and I was successfully connected. Could you tell what db server you tried it on? Of course, the app connects to my local db.
Own applications running on AWS that use Sequelize.
I am sorry, but even if you can connect with pg-promise, I have no way to find out why it wouldn't work with Sequelize without a repro.
Reacted by Osoian Marcel, Long Nguyen, new people, Leonardo Felicissimo, Arpit Jain, kramer65, RyccoSN, Alastair Taft, Leandro Hoffmann, Cecilia Lam and 52 more
Same issue here. The connection is established but when the connection of any connection is lost, the pool is getting smaller and after death of all threads application goes down. We had no troubles with this with 3+ version of Sequelize, so I guess it's not problem of db connection. Also tried downgrade from 4.2.1 (latest) to 4.1.0 and same problem.
Reacted by Idris Mokhtarzada, Ilia Ruchevskii, Leonardo Felicissimo, new people, kramer65, RyccoSN, Leandro Hoffmann, Johnny, ws2356, Joshua Turner and 3 more
I have fixed the issue by maximizing the acquire option of pool configuration in sequelize
pool: {max: 5,min: 0,idle: 20000,acquire: 20000}
I guess Amazon RDS runs a lot of checks when asking for resources.
Also I am running the Free Tier of Amazon RDS.
Reacted by pavelkrcil, Avraham Tauberman, Dana Majid, Kuriel, qeesung, Lovell, Lucas Astrada, Jon Austin, iamjoyce, Eugene Shilin and 62 more
Reacted by dakdreams, Sanjay Achar, rabihiawaludin, Eva Pace, wangjingbo, Quang Ninh, Widada, Sunny Singh, Ali, alanjonesrios and 4 more
Reacted by rabihiawaludin, Eva Pace, wangjingbo, Quang Ninh, Widada, Sunny Singh, Scarlett, alanjonesrios, Elton Marques dos Santos and Juanu
Reacted by Sanjay Achar, rabihiawaludin, Eva Pace, wangjingbo, Vic de Guzman, Quang Ninh, Mitesh Sondhi, solution-chip, Widada, Sunny Singh and 11 more
Reacted by alanjonesrios, Kevin Danikowski, Kayo Lima, Juanu and Hendra Agil
Reacted by IRADUKUNDA Allelua Fiacre, archunanswaas, Kayo Lima and Juanu
I'm having the exact same issue! The above pool configuration did NOT work. In our production environment, in a 24h period this error is logged ~5,000 times. It's been consistent for the last 27 days. I too am on the latest v4 of sequelize and using AWS RDS. It would be great to have this looked into more closely as it's a serious risk in the latest release.
Reacted by kramer65, Gbadebo Oyelakin, ws2356, Gerson Calienes, Seph Soliman and Jovanovic Jovan
We upgraded to v5 as well. With no further sequelize (i. e. pooling) configuration other than that, we still get SequelizeConnectionAcquireTimeoutError: Operation timeout. Anecdotally, this timeout-ing seems to occur less, but haven't measured/monitored closely in our deployment.
Will update if we find a configuration or bugfix that eradicates our issues completely!
Reacted by Pedro Augusto de Paula Barbosa and Sangbeom Han
Turns out that we had a case of a concurrent nested transaction stalling a parent transaction, which resulted in a connection to hang on the parent transaction. When this case was reached n (where n = our max pool size) times that filled our pool with hanging connections, we'd get bursts of time that ended up degrading our service. We have health checker that will kill degraded instances, so this didn't give us complete downtime; instantiating new instances put off the problem until we reached that all-connections-in-pool-hanging state again.
We solved this by refactoring to split out the concurrent nested transaction from the parent (they weren't actually dependent on each other). Our initial code would have the nested transaction fail silently, leaving the parent waiting for it to finish. Also did a pass through the codebase to ensure that anywhere we were doing nested transaction calls, we were passing transactions properly.
We were able to replicate the issue in staging doing something similar to the code in the issue above, so I'm fairly confident this was our issue; after shipping our fix below we aren't seeing the same results.
Disclaimer: may or may not understand the full intricacies of connections/transactions/pooling, so take with a grain of salt!
Reacted by Pedro Augusto de Paula Barbosa, Yuri Oliveira, Sasha Kalmikov, Sangbeom Han and Nicolas Prugne
There's always been some issues with having N concurrent transactions where N is greater than your pool.max, i forgot the specific case but you could end up with code waiting for a connection to do something to finish up the transactions but the transactions had all the connection etc.
For reference my company has been running Sequelize against RDS for 4+ years with no issues, if there were ever connection issues it's cause there were actually connection issues.
Reacted by Pedro Augusto de Paula Barbosa, b and Gustaf Lindqvist
as @BTROO and @mickhansen said, This issue happened when the count of concurrent transactions is greater than your pool.max. I'm trying to describe it in a simple way, Let's see what happens: What is the connection pool?
When your application needs to retrieve data from the database, it creates a database connection. Creating this connection involves some overhead of time and machine resources for both your application and the database. Many database libraries and ORM's will try to reuse connections when possible so that they do not incur the overhead of establishing that DB connection over and over again. The pool is the collection of these saved, reusable connections that
what is concurrent transactions?
in a simple way, if you are trying to run some CRUD command in a nested transaction, it means you are using concurrent transactions. let's assume our Sequlize config is like this:
let nested = function() {
// here we are making a new transaction:
return db.sequelize.transaction(t1 => {
// as you see in bellow command we won't use t1 transaction
// which means our DB (in my case postgress) run below command in other transaction
// and this is where the problem lies!
// when we'll execute nested function, we'll create a concurrent transaction per each call
return db.user.findOne();
});
};
const arr = [];
for (let i = 0; i < 7; i++) {
arr.push(nested());
}
Promise.all(arr)
.then(() => {
console.log('done');
})
.catch(err => {
console.log(err);
});
We've bumped into the same error. It's weird, but we don't have any transactions in that piece of code. It looks like a bunch of asynchronous queries to the DB, two of them use sequelize.query() to query data and the rest 8 are made with models. I don't know why exactly, but calling one of the .query() after the others resolved somehow fixed the issue. So, we first run all those 9 queries simultaneously, and after they resolved we run the latest one. Only this worked for us.
I was also getting the "Unhandled rejection SequelizeConnectionAcquireTimeoutError: Operation timeout error." I tried everything and the only one solution I got remove setınterval commands:
Activity
felixfbecker commentedon Jul 5, 2017
I cannot reproduce the error. Obviously there was a timeout in connecting to the DB server, it doesn't look like a bug in Sequelize to me.
clutariomark commentedon Jul 5, 2017
Tried the same endpoint and other credentials using pg-promise, and I was successfully connected. Could you tell what db server you tried it on? Of course, the app connects to my local db.
felixfbecker commentedon Jul 5, 2017
Own applications running on AWS that use Sequelize.
I am sorry, but even if you can connect with pg-promise, I have no way to find out why it wouldn't work with Sequelize without a repro.
clutariomark commentedon Jul 5, 2017
please use this and try if you can reproduce the same error
postgres://testuser:[email protected]:5432/safepath
Already tried connecting to it using node-postgres and it worked, same error for sequelize though.
afituri commentedon Jul 6, 2017
I have the same exact issue!
afituri commentedon Jul 6, 2017
pavelkrcil commentedon Jul 8, 2017
Same issue here. The connection is established but when the connection of any connection is lost, the pool is getting smaller and after death of all threads application goes down. We had no troubles with this with 3+ version of Sequelize, so I guess it's not problem of db connection. Also tried downgrade from 4.2.1 (latest) to 4.1.0 and same problem.
afituri commentedon Jul 8, 2017
I have fixed the issue by maximizing the acquire option of pool configuration in sequelize
I guess Amazon RDS runs a lot of checks when asking for resources.
Also I am running the Free Tier of Amazon RDS.
swordfish444 commentedon Jul 10, 2017
I'm having the exact same issue! The above pool configuration did NOT work. In our production environment, in a 24h period this error is logged ~5,000 times. It's been consistent for the last 27 days. I too am on the latest v4 of sequelize and using AWS RDS. It would be great to have this looked into more closely as it's a serious risk in the latest release.
swordfish444 commentedon Jul 10, 2017
@felixfbecker It looks like this is the same as #7882
Also #7616 is likely related to the same problem.
pavelkrcil commentedon Jul 10, 2017
@afituri This saved my life. Thank you!
philipdbrown commentedon Jul 10, 2017
Yeah, I'm having this same issue on a DigitalOcean server as well. I've tried the configuration from above with no luck.
118 remaining items
polaroi8d commentedon Jul 15, 2019
@Joshua-Turner are u successfully migrated to v5 and find everything perfect? Do you have any experience with the v5?
lancedikson commentedon Jul 15, 2019
We have upgraded to v5 and seems like it helped for some reason. But it was such a shot in the dark.
bbbeeeee commentedon Aug 1, 2019
We upgraded to v5 as well. With no further sequelize (i. e. pooling) configuration other than that, we still get
SequelizeConnectionAcquireTimeoutError: Operation timeout. Anecdotally, this timeout-ing seems to occur less, but haven't measured/monitored closely in our deployment.Will update if we find a configuration or bugfix that eradicates our issues completely!
bbbeeeee commentedon Aug 2, 2019
Update:
Found this issue yesterday #10976
Turns out that we had a case of a concurrent nested transaction stalling a parent transaction, which resulted in a connection to hang on the parent transaction. When this case was reached
n(wheren= our max pool size) times that filled our pool with hanging connections, we'd get bursts of time that ended up degrading our service. We have health checker that will kill degraded instances, so this didn't give us complete downtime; instantiating new instances put off the problem until we reached that all-connections-in-pool-hanging state again.We solved this by refactoring to split out the concurrent nested transaction from the parent (they weren't actually dependent on each other). Our initial code would have the nested transaction fail silently, leaving the parent waiting for it to finish. Also did a pass through the codebase to ensure that anywhere we were doing nested transaction calls, we were passing transactions properly.
We were able to replicate the issue in staging doing something similar to the code in the issue above, so I'm fairly confident this was our issue; after shipping our fix below we aren't seeing the same results.
Disclaimer: may or may not understand the full intricacies of connections/transactions/pooling, so take with a grain of salt!
mickhansen commentedon Aug 5, 2019
There's always been some issues with having
N concurrent transactionswhereNis greater than yourpool.max, i forgot the specific case but you could end up with code waiting for a connection to do something to finish up the transactions but the transactions had all the connection etc.mickhansen commentedon Aug 5, 2019
For reference my company has been running Sequelize against RDS for 4+ years with no issues, if there were ever connection issues it's cause there were actually connection issues.
derakhshanfar commentedon Aug 21, 2019
as @BTROO and @mickhansen said, This issue happened when the count of concurrent transactions is greater than your pool.max. I'm trying to describe it in a simple way, Let's see what happens:
What is the connection pool?
what is concurrent transactions?
in a simple way, if you are trying to run some CRUD command in a nested transaction, it means you are using concurrent transactions. let's assume our Sequlize config is like this:
we are trying to run this command:
The workaround is just run db.user.findOne() in t1 transaction to avoid concurrent transactions and it will be fixed:
db.user.findOne({transaction: t1})you can also use continuation-local-storage to pass transaction automatically, just check below link:
https://sequelize.org/master/manual/transactions.html#concurrent-partial-transactions
ashutoshpw commentedon Sep 9, 2019
In pool settings just keep the minimum count to about 2 to 4.
This solved the issue for me.
hrabizadeh commentedon Dec 29, 2019
Thanks, Your solution solved my issue.
intellix commentedon May 29, 2020
I don't understand how solving acquire timeout errors is fixed by reducing the timeout from the default of 60 seconds to 20?
#7884 (comment)
edit: because the default is actually 10 sec... not sure where I saw a default of 60
val-pidburtnyi commentedon Sep 1, 2020
I guess the key here is that 2 connections are never released ("min: 2")...
johnfazzietempus commentedon Oct 21, 2020
Looks like the acquire timeout is 60 seconds in sequelize v5 and v6.
fix sequelize#7884
fix sequelize#7884 TimeoutError: ResourceRequest timed out
yusufbayrk commentedon Jun 3, 2022
I was also getting the "Unhandled rejection SequelizeConnectionAcquireTimeoutError: Operation timeout error." I tried everything and the only one solution I got remove setınterval commands:
setInterval(
( ) => sequelize.query("REFRESH MATERIALIZED VIEW tables"),
2601e3,
I remove this commands and problem is solved. I hope your solution will be solved very soon.