gatsby-uc / gatsby-source-strapi

Gatsby source plugin for building websites using Strapi as a data source
MIT License
354 stars 182 forks source link

[SOLVED] Build (and Develop) fails randomly (ECONNRESET) #324

Closed barthofu closed 2 years ago

barthofu commented 2 years ago

The error

The error happens during the build just after fetching the data from Strapi. It is relatively random, and can take several shapes (also randomly):

Comments

Requirements

MRDRMUFN commented 2 years ago

Maybe try updating your Gatsby to 4.13.1 or later there was a race condition that caused random build failure during single threaded builds like Gitlab Runner or Netlify. https://github.com/gatsbyjs/gatsby/pull/35513

barthofu commented 2 years ago

[SOLVED]

After days and days of debugging we found that it was issued by NGINX (strapi side). Indeed, the plugin was spamming way to much (we have quite a huge strapi db and nearly 6.5k uploads) the server, and nginx would randomly block requests. We solved it by optimizing the nginx server.

MRDRMUFN commented 2 years ago

Any chance you mind reporting what optimization you made to NGINX?

mikevanis commented 2 years ago

Ditto, I have the exact same problem. @barthofu what did you do on the nginx side to fix this?

mikevanis commented 2 years ago

Ok, I think I figured out what the problem was on my setup. I noticed that when the build was crashing, this would come up on the nginx logs:

20:08:10 [alert] 10#10: *3768 512 worker_connections are not enough while connecting to upstream, client: xxx.xxx.xxx.xxx, server: mydomain.world, request: "GET /api/upload/files?filters[url]=/uploads/img.JPG HTTP/1.1", upstream: "xxxxxxx", host: "xxxxxxx:1337"

I increased worker_connections in my nginx.conf like this:

events {
  worker_connections 2048;
}

Clearly gatsby build was requesting all my images at the same time (I have about 500), and the worker ran out of connections. Increasing the number of connections did the trick. @MRDRMUFN I hope this helps you <3

barthofu commented 2 years ago

Oh yeah really sorry i haven't saw you answers until now 😭 But yeah it was the max number of worker_connections that did the trick 🙏

Sorry once again...