FetchError: socket hand up during Nuxt generation

Hi
during Nuxt routes generation on Netlify I'm getting the following error for some routes.

It doesn't happen always on the same pages but randomly, in different pages each generation.

FetchError: request to https://xxxx.cdn.prismic.io/api/v2/documents/search?page=1&pageSize=1&lang=en-US&ref=Ybi1ZRUAACgAfuP0&q=%5B%5Bat(document.type%2C%20%22footer%22)%5D%5D failed, reason: socket hang up

Why? How can I solve this issue?

Thanks

Hey @dev30, thanks for reaching out.

How and where are you doing the query for these pages on your project? This might help us identify the source of the error.

Hi Pau,
the query of each page is called in the asyncData.

But, I also query prismic in nuxtServerInit to fetch common parts' content like footer and header that also contains content relationship fields.

This is the funciton I call in nuxtServerInit

  async getFooterData({ commit }, lang) {
    const footer = { ...await this.app.$prismic.api.getSingle('footer', { lang }), navs: [] }
    const footerPromises = footer.data.body.map(async (slice, index) => {
      if (slice.slice_type === 'content_type_list') {
        const slicePromises = slice.items.map(async (item, index) => {
          const itemData = await this.app.$prismic.api.getByUID(item.item.type, item.item.uid, { lang })
          footer.navs[index] = { title: itemData.data.navigation_title, items: itemData.data.body, id: item.item.uid }
        })
        await Promise.all(slicePromises)
      }
    })
    await Promise.all(footerPromises)
    commit('setFooter', footer)
  }

Hello @dev30, maybe the problem is coming from this piece of code:

const slicePromises = slice.items.map(async (item, index) => {
          const itemData = await this.app.$prismic.api.getByUID(item.item.type, item.item.uid, { lang })
          footer.navs[index] = { title: itemData.data.navigation_title, items: itemData.data.body, id: item.item.uid }
        })

Async calls inside the a map functions make requests at the same time and that can overload the server. One way to handle this is susing a library like PQueue

const adminEmailsQueue = new PQueue({
  concurrency: 1,
  interval: 4000,
  intervalCap: 1,
})
let discourseAdminsWithEmails = await Promise.all(
  discourseAdminsWithoutBots.map((a) => {
    return adminEmailsQueue
      .add(() =>
        nodeFetch(
          `${discourseURL}/users/${a.username}/emails.json`,
          options
        ).then((res) => res.json())
      )
      .then((r) => Object.assign(r, a))
      .catch((e) => console.error(e))
  })
)

Hi, thank you!

I'm now using reduce instead of map and also caching the NuxtServerInit content in order to get common footer's data only at first page generation. Furthermore I added an interval to Nuxt generation to generate a page (and so call prismic) every 300ms instead of 0.

I'm not getting socket error anymore but with some pages I'm getting this new error:

{"message":"request to https://xxxxx.cdn.prismic.io/api/v2/documents/search?page=1&pageSize=20&lang=it-it&fetch=post.category&ref=YcrajBEAACIA6Ke5&q=%5B%5Bat(my.post.uid%2C%20%22post-slug%22)%5D%5D failed, reason: read ECONNRESET","type":"system","errno":"ECONNRESET","code":"ECONNRESET"}'

Any ideas?
Thanks

This may be related to how you're managing the requests. Take a look at this related Stackoverflow thread:

Requests are made using the prismic SDK in asyncData of each page.

It might be a caching issue. Have you tried removing the cache?

Removing cache didn't help.

I'm still getting the following error for different pages and custom types:

{"message":"request to https://xxx.cdn.prismic.io/api/v2/documents/search?page=1&pageSize=100&lang=en-US&orderings=%5Bmy.post.date%20desc%5D&fetchLinks=blog_category.name&ref=123&q=%5B%5Bat(document.type%2C%20%22post%22)%5D%5D failed, reason: socket hang up","type":"system","errno":"ECONNRESET","code":"ECONNRESET"}'

Can you please send us the URL of your repository? We'll escalate this issue o the dev team.

Please take a look at this similar thread. This type of error are specific to each project code, but it might give you an idea of where you can start troubleshooting the error while generating the project again: