Strapi service that stops when it loses its database connection

System Information
  • Strapi Version: 3.6.8
  • Operating System: Red Hat Enterprise Linux - 8.4 (Ootpa)
  • Database: postgres
  • Node Version: 12.22.1
  • NPM Version: 6.14.12


I’m currently experiencing a difficulty in deploying Strapi. Indeed, when the latter loses its connection to the postgres database with which it communicates, the following error appears / the service stops.

debug ⛔️ Server wasn't able to start properly.
error Error: connect ECONNREFUSED

According to the documentation and user feedback, the service seems to be able to be launched without a connection to a database. Is this the case? If so, how did you do it?

I thought (from the release notes) that upgrading to 3.6.8 would solve the problem, but no. Likewise, I tried following guidelines such as these (Database connection timeouts after some time and strapi crashed · Issue #8436 · strapi/strapi · GitHub), but it didn’t work.

Thank you in advance for your feedback.
Have a lovely day.

That specific error means it can contact the database but the database is refusing, most likely use to a bad username or password.


Thank you for this feedback, I have the same understanding of the error.
However, I thought (according to the elements available on the internet) that Strapi could be launched without a connection to a database and automatically detect when it’s established.
Is this possible according to you?

No it has to be launched with the connection, but if the connection is lost while it’s running and restored later it should begin to function again without an application reboot.

(you can’t change the username/pass while it’s running, that will require an app reboot)

1 Like

Thank you for these details.
Do I have to set up a specific configuration so that Strapi has this behavior if loss of its connection to the database?
Currently, I can’t reproduce this on my side. When Strapi loses its connection to the database, the error detailed above is displayed and the service stops.

No, it’s just the stateless nature of how Strapi works. If it loses the connection to the database during a request then it will fail but if the connection is restored and a new request comes in then it should function as normal.

There is a set of pooled connections for SQL databases that will obviously be killed but during the request Strapi should attempt to rebuild this pool like normal.