In sequelize connection I am getting operation timeout error. How to fix this issue

8.5k views Asked by At

I am using Sequelize ORM for connecting databases using NODE JS and PostgreSQL. When I request concurrently to the server it's throwing an error ConnectionAcquireTimeoutError [SequelizeConnectionAcquireTimeoutError]: Operation timeout. So, I search it how to fix this issue. many of the given solutions to increase to acquire count or increase the connection pool count. is it the right solution?

Sequalize Config

  pool: {
    max: 5,
    min: 0,
    acquire: 30000,
    idle: 10000
  }

Sequelize Version : 6.6.2

When I increase the acquire count and connection pool count it's throwing same error

1

There are 1 answers

0
Valentin On

You can use the param retry in Sequelize option to handle what to do if you got this error

 retry: {
    match: [/Deadlock/i, Sequelize.ConnectionError], // Retry on connection errors
    max: 3, // Maximum retry 3 times
    backoffBase: 3000, // Initial backoff duration in ms. Default: 100,
    backoffExponent: 1.5, // Exponent to increase backoff each try. Default: 1.1
  },

Also, there is a tricky thing with Sequelize, if you use transactions (I think you do) you should not use await/async but promise transactions

If your transaction use await/async, your maximum concurrent transaction will be your pool.max value, so any n+1 transaction will be rejected by a deadlock

If your transaction use Promise, your n+1 transaction will be queued (more delayed than queued) and will not be deadlocked

https://lightrun.com/answers/sequelize-sequelize-deadlock-on-multiple-transactions

it should solve some of your problem :)