Strapi database migrations on startup - race condition

System Information
  • Strapi Version:
  • Operating System:
  • Database:
  • Node Version:
  • NPM Version:
  • Yarn Version:

Hi, I needed some time to figure why my db is exhausted connection pools. My background is devops not JS developer.

We are running Strapi in cluster mode using PM2. Reason for this is today usually cloud instances come with two or more CPUs and we want to use all of them.

But lets say even without PM2 cluster mode if we want to run Strapi in a loadbalanced environment this “race condition” is happening.

What I understand from a devops perspective is that when Strapi is started it will check to see if any DB migrations is needed and run them. But since we run multiple processes at the same time this leads to race conditions.

Anyone having similar issues? How do you solve them?

1 Like