sequelize / sequelize-pool

Resource pool implementation. It can be used to throttle expensive resources.
Other
38 stars 17 forks source link

Fix acquire not resolving after destroying available resources #44

Closed kurayama closed 3 years ago

kurayama commented 3 years ago

We're hitting an issue in sequelize when using postgres's idle_in_transaction_session_timeout. When the code inside a transaction hits the timeout it causes the connection to be destroyed due to a protocol error and waiting connections throw a ConnectionAcquireTimeoutError after 60s (the default acquireTimeoutMillis in sequelize).

It's easily reproducible using pool.max: 1 and:

await Promise.allSettled([
  sequelize.transaction(async transaction => { 
    await sequelize.query('SET LOCAL idle_in_transaction_session_timeout = 50', { transaction }); 
    await new Promise(resolve => setTimeout(resolve, 100)); 
    await sequelize.query('SELECT 1', { transaction }); 
  }), 
  sequelize.query('SELECT 1')
]);

Resolves to:

[
  {
    reason: DatabaseError [SequelizeDatabaseError]: Client has encountered a connection error and is not queryable
    ...
    status: 'rejected'
  },
  {
    reason: ConnectionAcquireTimeoutError 
    ...
    status: 'rejected'
  }
]

Expected behaviour would be for the second query to be fulfilled.

sushantdhiman commented 3 years ago

+ sequelize-pool@7.1.0

kurayama commented 3 years ago

Thanks @sushantdhiman 😉