0

My whole node app crashes with "Unhandled promise rejection" SequelizeConnectionRefusedError when for some reason (ex. heavy db load) the database rejects the connection.

I want to find a solution so that the app does not crash and if possible try to reconnect.

This is how I connect to the database

const db = new Sequelize(DATABASE_URL, {
 logging: false,
 pool: {
 max: parseInt(NUMBER_PG_CONNECTIONS),
 min: 1,
 idle: 10000,
 acquire: 30000,
},
dialectOptions: {
 ssl: {
  require: true,
 },
},
ssl: true,
});
perrosnk
  • 835
  • 2
  • 13
  • 23
  • Does this answer your question? [What is an unhandled promise rejection?](https://stackoverflow.com/questions/40500490/what-is-an-unhandled-promise-rejection) – esqew Mar 24 '21 at 13:03
  • No, it doesn't. There is nowhere I can catch this error. In fact, there is this closed issue https://github.com/sequelize/sequelize/issues/11412 that somebody says that sequelize is expected to do so. – perrosnk Mar 24 '21 at 13:09

1 Answers1

0

Well you could consider things like nodemon, forever or pm2 or similar - which should guarantee that your server stays up (recovers after a crash).

However there is often more to it than that. If for instance you have lost connectivity to your database do you really want your node server to be running? Or if you are running out of connections then there is perhaps a design issue/bug whereby connections are being leaked?

batman567
  • 826
  • 2
  • 12
  • 23