Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (19.1k points)

I'm having an issue at the moment where I'm trying to make use of a Serverless Aurora database as part of my application.

The problem is essential that when the database is cold, time to establish a connection can be greater than 30 seconds (due to db spinup) - This seems to be longer than the default timeout in Sequelize (using mysql), and as far as I can see I can't find any other way to increase this timeout or perhaps I need some way of re-attempting a connection?

Here's my current config:

const sequelize = new Sequelize(DATABASE, DB_USER, DB_PASSWORD, {

    host: DB_ENDPOINT,

    dialect: "mysql",

    operatorsAliases: false,

    pool: {

      max: 2,

      min: 0,

      acquire: 120000, // This needs to be fairly high to account for a 

      serverless db spinup

      idle: 120000,

      evict: 120000

    }

});

A couple of extra points: Once the database is warm then everything works perfectly. Keeping the database "hot", while it would technically work, kind of defeats the point of having it as a serverless db (Cost reasons). I'm open to simply having my client re-try the API call in the event the timeout is a connection error.

Here are the logs in case they help at all.

{

"name": "SequelizeConnectionError",

"parent": {

    "errorno": "ETIMEDOUT",

    "code": "ETIMEDOUT",

    "syscall": "connect",

    "fatal": true

},

"original": {

    "errorno": "ETIMEDOUT",

    "code": "ETIMEDOUT",

    "syscall": "connect",

    "fatal": true

}

} 

1 Answer

0 votes
by (44.4k points)

Using dialectOptions prop on the options object, this can be done and it seems to work:

dialectOptions: {

  connectTimeout: 60000

}

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer
0 votes
1 answer

Browse Categories

...