Timeout on external API calls while building our website

Hello everyone!
We are deploying a static site generated with NuxtJS to Netlify, but half the times the process starts to generate static pages our external APIs calls to Contentful timeout. This is one of the error messages in the build log:

ERROR   /products/odeon-vertical-black
12:32:32 PM: Error: timeout of 30000ms exceeded
12:32:32 PM:     at createError (/opt/build/repo/node_modules/contentful/dist/contentful.node.js:941:15)
12:32:32 PM:     at Timeout.handleRequestTimeout (/opt/build/repo/node_modules/contentful/dist/contentful.node.js:360:16)
12:32:32 PM:     at ontimeout (timers.js:436:11)
12:32:32 PM:     at tryOnTimeout (timers.js:300:5)
12:32:32 PM:     at listOnTimeout (timers.js:263:5)
12:32:32 PM:     at Timer.processTimers (timers.js:223:10)

The error is triggered by Contentful official Javascript SDK after waiting 30 seconds for a response.
This problem does not occur on our local machines, so i’m pretty confident that Contentful API never takes so long to respond ( that would be a huge problem for a content delivery API ).
I’m inclined to believe that it’s a problem with Netlify infrastructure, maybe we are flooding the kernel with too many open sockets? We are generating ~50 pages, so it’s not really a big number.

Has anyone experienced a similar issue?

You’d need to make sure your endpoint starts sending data (at least HTTP response headers) within 30 seconds. Best practice is to have API calls that return within 30 seconds, but your endpoint MUST at least start sending, otherwise our build env shuts down the idle connection at that point.

Thanks for the reply. We were able to avoid timeouts by setting an interval of 2 seconds between every route render. Although i don’t think its a Contentful issue, as we are connecting to their Delivery API which should be cached behind a CDN.
I’m still afraid it’s a limit on how many concurrent connections NodeJS can handle, but as we still have a reasonable build time i don’t think we are going to investigate further.

Thanks so much for the follow-up! Unexpected that it is a node limitation manifesting in that way, but great sleuthing!

Thanks for sharing the solution. I recently run into the exact same issue, could only resolve it by updating interval.


If you are facing the same issue, FYI I’ve fixed it on my side by upgrading the Contentful npm dependency to the latest.
I’m now able to build 1000+ pages without any interval :fire: