sequelize: ResourceRequest timed out - connection not reestablished after db restarted

What you are doing?

We’re running into an issue where Sequelize will not reconnect to the database after the database is stopped and started again. If you want, you can try hosting a local mssql database using this tutorial and running the following code, and following the steps I provide below:

https://medium.com/@reverentgeek/sql-server-running-on-a-mac-3efafda48861

const options = {
  host: 'localhost',
  dialect: 'mssql',
  pool: {
    max: 1,
    min: 0,
    idle: 5000,
    acquire: 5000
  },
  dialectOptions: {
    requestTimeout: 5000
  },
  isolationLevel: 'READ UNCOMMITTED'
};

const Sequelize = require('sequelize')

const sequelize = new Sequelize('testing', 'sa', 'P@55w0rd', options);

setInterval(() => {
  sequelize
    .query("SELECT 'connection is successful'", {
      type: Sequelize.QueryTypes.SELECT
    })
    .then((results) => {
      console.log(results);
    })
    .catch((err) => {
      console.log(err);
    })
}, 5000);

Steps after code is running and mssql container is running:

  1. stop the container
  2. wait until an interval fires and throws an error
  3. start the container
  4. notice that all future queries result in timeout errors

I’m pretty sure this should reject, but I’m not too sure: https://github.com/sequelize/sequelize/blob/master/lib/dialects/abstract/connection-manager.js#L98

What do you expect to happen?

Sequelize to reconnect and have queries work as normal.

What is actually happening?

Sequelize fails to reconnect the created pool resource.

Dialect: mssql, but probably all Database version: XXX Sequelize version: 4.4.2

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 19
  • Comments: 19 (4 by maintainers)

Commits related to this issue

Most upvoted comments

I believe that PR is fixing that issue. https://github.com/sequelize/sequelize/pull/8022 How can we get that merged into the next release?

My colleague has made some progress identifying a possibly related error: https://github.com/sequelize/sequelize/issues/8756

I am also experiencing this problem. I think bad connections are not getting removed from the pool and the pool is filling up. I get similar problems after a couple days in production.

I have investigated this issue, it appears connect event is never fired after database restart. This cause acquire call to never finish and pool keep reporting timeout because none of the resource requests are finishing.

This issue is only appearing at pool.max: 1 all other configuration are irrelevant. For production machines max may be set to large value but this issue will appear once pool is saturated.

Fix was rejecting connection when end event is called before connect.

After this patch I was able to reconnect to database even with restarting local instance, queries continued normally. Please let me know if https://github.com/sequelize/sequelize/pull/9037 fix this issue or not 😃

@sushantdhiman #8330 does not fix this issue. Still experiencing the ResourceRequest timed out error after SQL Server restart using sequelize@4.9.0. #8022 Fixes this issue, and we’re patiently waiting on it to be merged 😄

Could you please re-open this ticket until #8022 is merged? I’ll be happy to contribute in any way possible.