Skip to content

Resource Request Timed out #8133

Closed

Description

@jeremyklein

What you are doing?

I have a script which parses XML and loads them into a database. This script previously worked with Postgres SQL. I must switch to MSSQL. I have the following db connection settings:

// code here
    { "username":username,
      "password":"password,
      "database":database,
      "host":host,
      "port": "post,
      "dialect":"mssql",
     "connectionTimeout": 0,
      "pool":{
         "max": 1,
         "min": 1,
         "idle": 200000,
        "acquire": 200000
      },
    "retry":{"max": 3},
    "logging": false,
    "dialectOptions": {
                "requestTimeout": 0,
     },
     "options":{
                "port": port
     }
}

What do you expect to happen?

I wanted the data to load into the database.

What is actually happening?

The records load for approximately 4 minutes. Then i get the following error:

{ TimeoutError: ResourceRequest timed out
    at ResourceRequest._fireTimeout (/home/jcook/riqi_provider_directory/node_modules/sequelize/node_modules/generic-pool/lib/ResourceRequest.js:59:17)
    at Timeout.bound [as _onTimeout] (/home/jcook/riqi_provider_directory/node_modules/sequelize/node_modules/generic-pool/lib/ResourceRequest.js:8:15)
    at ontimeout (timers.js:469:11)
    at tryOnTimeout (timers.js:304:5)
    at Timer.listOnTimeout (timers.js:264:5) name: 'TimeoutError' }

Some data continues to load, but it looks like not all of my records are inserted into the database.

Dialect: mssql
Database version: 2008
Sequelize version: 4.1.0

Activity

  1. jeremyklein commented on Aug 17, 2017

    @jeremyklein
    Author

    Increasing the max pool size allowed the data to be loaded. I would prefer not to need 100 connections to the database to load this data.

  2. xdamman commented on Sep 5, 2017

    @xdamman

    I have the same issue but increasing the max pool size didn't help. I'm using the very latest version (4.8 and cli 2.8.0)

  3. jeremyklein commented on Sep 5, 2017

    @jeremyklein
    Author

    Which verson of Tedious are you using?

  4. xdamman commented on Sep 6, 2017

    @xdamman

    @jeremyklein tedious? Not using it / never heard of it. Using Postgres 9.6 btw

  5. xdamman commented on Sep 8, 2017

    @xdamman

    Still having the same issue with sequelize 4.8.2 and sequelize cli 3.0.0 (and Postgres 9.6 on MacOSX)

  6. xdamman commented on Sep 8, 2017

    @xdamman

    Here is how I solved it:

    I've added { concurrency: 10 } to Promise.map(array, Promise, { concurrency: 10 });

  7. idris commented on Jan 15, 2018

    @idris
    Contributor

    I can't seem to get rid of the ResourceRequest timed out errors. I've tried various settings. Here are my current pool settings:

        pool: {
          max: 5,
          min: 0,
          idle: 20000,
          acquire: 40000,
          evict: 20000,
        },
    

    I'm using RDS Postgres. If it's exceeding the 40 second acquire time I set, does that essentially mean that all 5 connections are busy for 40 seconds?

  8. Celadora commented on Jan 24, 2018

    @Celadora

    We are experiencing this problem across all services now (that had previously been working fine for over a year) that use Sequelize to connect to a Digital Ocean droplet (where the MySQL database is located). It seems like the more the service connects to the database, the sooner the error appears. After it appears the services must be restarted.

  9. idris commented on Jan 24, 2018

    @idris
    Contributor

    @Celadora if I understand this issue correctly, this is just a matter of tweaking the pool settings. In v2 (not sure about v3), there was no acquire timeout, so if all connections in the pool were busy, your app would just wait forever until a connection freed up. This was obviously not ideal. Although it did not throw an error, it was dangerous.

    In v4, you need to decide on timeouts that make sense for your app. If you want the old behavior, I think the closest thing would be to increase acquire to something ridiculously high like 1000000. Obviously, that's silly. My real recommendation would be to increase the pool max to something higher (I used 30), and set acquire to something reasonable for your app.

    I think the main root cause for this whole issue is long-running queries. If you have a pool max of 5 connections, and you have 5 concurrent queries going, with each query taking 30 seconds, your acquire is going to have to wait at least 30 seconds to get a connection. Those queries can also queue up a bit, thereby exacerbating the problem.

    Hope that helps, and I hope everything I said is accurate. Anyone, please correct me if I'm wrong on any of that.

  10. Celadora commented on Apr 15, 2018

    @Celadora

    @idris Thank you very much! Your advice corrected the issue.

  11. mkaufmaner commented on Jul 2, 2019

    @mkaufmaner
    Contributor

    For those of you still using v4 of Sequelize, this problem may have been fixed by v4.44.1.

    See PR: #11140
    See Issue: #11139

  12. ndangles commented on Aug 29, 2020

    @ndangles

    My issue was that I was using unmanaged transactions which require manual calls of commit and rollback and I was forgetting to call rollback in the catch block of my try/catch after throwing an error resulting in a hanging transaction which eventually returned SequelizeConnectionAcquireTimeoutError. Stripped down example below.

    Faulty Code

    app.post("/signup", async (req, res) => {
      const t = await sequelize.transaction();
    
      try {
        const { first_name, last_name, email } = req.body;
    
        const user = await Users.findOne({
          where: {
            email,
          },
        });
    
        if (user) {
          throw new Error("A user with that email already exists");
        }
    
        let newUser = await Users.create(
          {
            first_name,
            last_name,
            email,
          },
          { transaction: t }
        );
    
        await t.commit();
    
        res.status(200).send({});
      } catch (e) {
        // MISSING TRANSACTION ROLLBACK HERE
    
        res.status(500).send({});
      }
    });
    

    Correct Code

    app.post("/signup", async (req, res) => {
      const t = await sequelize.transaction();
    
      try {
        const { first_name, last_name, email } = req.body;
    
        const user = await Users.findOne({
          where: {
            email,
          },
        });
    
        if (user) {
          throw new Error("A user with that email already exists");
        }
    
        let newUser = await Users.create(
          {
            first_name,
            last_name,
            email,
          },
          { transaction: t }
        );
    
        await t.commit();
    
        res.status(200).send({});
      } catch (e) {
        await t.rollback(); // THE FIX
        res.status(500).send({});
      }
    });
    
  13. miguelHM63 commented on Jul 12, 2022

    @miguelHM63

    if (user) {
    throw new Error("A user with that email already exists");
    }

    @ndangles can you send this error to your client? because that error would jump to the catch block, something similar happened to me and I had to handle the errors of the try block, in the catch block

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions