Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intermittent Build Failures at Merge Worker State #259

Closed
panzacoder opened this issue Feb 3, 2022 · 28 comments
Closed

Intermittent Build Failures at Merge Worker State #259

panzacoder opened this issue Feb 3, 2022 · 28 comments
Labels
bug Something isn't working

Comments

@panzacoder
Copy link

Describe the bug

Beginning when I upgraded to Gatsby v4.6 I started getting errors when building on Netlify. Most builds succeed, and then all of a sudden all builds fail. Sometimes clearing the cache fixes it, sometimes not. Now, a content change caused my production deploy to fail twice in a row.

I read that this might have been a regression, so I downgraded to 4.5, which fixed it initially but now build failures are happening again.

Steps to reproduce

Build gatsby site on netlify with v4.5 or v4.6

Expected behavior

A successful build.

Configuration

module.exports = {
flags: {
// FAST_DEV: true,
PRESERVE_FILE_DOWNLOAD_CACHE: true,
PARALLEL_SOURCING: true,
},
plugins: [
gatsby-plugin-react-helmet,
gatsby-plugin-extract-schema,
// {
// resolve: gatsby-plugin-sharp,
// options: { defaults: { placeholder: 'none', quality: 90 } },
// },
// babel-plugin-remove-graphql-queries, // for use with storybook
gatsby-plugin-advanced-sitemap,
// gatsby-plugin-webpack-bundle-analyser-v3,
// gatsby-plugin-preload-link-crossorigin,

// `gatsby-plugin-lint-queries`,
`gatsby-plugin-sharp`,
`babel-plugin-remove-graphql-queries`,
{
  resolve: `gatsby-plugin-feed`,
  options: {
    query: `
    {site {
      siteMetadata {
        title
        description
        siteUrl
        site_url: siteUrl
      }
    }}`,
    feeds: [
      {
        serialize: ({ query: { blog, site } }) => {
          return blog.nodes.map(
            ({ title, date, slug, body, category, author }) => ({
              title: title,
              description: body.childMarkdownRemark.excerpt,
              categories: [category],
              author: author,
              date: date,
              url: site.siteMetadata.siteUrl + '/blog/' + slug,
              guid: site.siteMetadata.siteUrl + '/blog/' + slug,
            })
          )
        },
        query: `
        {
    blog: allContentfulBlogPost(sort: { fields: [date], order: DESC }) {
      nodes {
        title
        category
        author{
          name
        }
        date
        slug
        body {
          childMarkdownRemark {
            excerpt
          }
        }
      }
    }
  }
    `,
        output: '/rss.xml',
        title: 'Blog RSS',
      },
    ],
  },
},
{
  resolve: `gatsby-theme-material-ui`,
  options: {
    webFontsConfig: null,
  },
},
{
  resolve: `gatsby-plugin-anchor-links`,
  options: {
    offset: -150,
  },
},
{
  resolve: 'gatsby-plugin-robots-txt',
  options: {
    sitemap: `${siteUrl}/sitemap/sitemap-pages.xml`,
    resolveEnv: () => CONTEXT,
    env: {
      production: {
        policy: [{ userAgent: '*' }],
      },
      'branch-deploy': {
        policy: [
          { userAgent: '*', disallow: ['/'] },
          { userAgent: 'Algolia Crawler', allow: ['/'] },
        ],
      },
      'deploy-preview': {
        policy: [
          { userAgent: '*', disallow: ['/'] },
          {
            userAgent: 'Algolia Crawler',
            allow: ['/ # Algolia-Crawler-Verif: STRING'],
          },
        ],
      },
    },
  },
},
{
  resolve: 'gatsby-plugin-intercom-spa',
  options: {
    app_id: GATSBY_INTERCOM_APP_ID,
    include_in_development: true,
    delay_timeout: 5000,
  },
},
{
  resolve: `gatsby-plugin-canonical-urls`,
  options: {
    siteUrl,
  },
},
{
  resolve: `gatsby-source-filesystem`,
  options: {
    name: `images`,
    path: `${__dirname}/src/`,
  },
},
{
  resolve: `gatsby-source-filesystem`,
  options: {
    name: `air_docs`,
    path: `${__dirname}/docs/`,
  },
},
{
  resolve: 'gatsby-plugin-react-svg',
  options: {
    rule: {
      include: /assets\/svg/,
    },
  },
},
{
  resolve: `gatsby-transformer-sharp`,
},
{
  resolve: `gatsby-transformer-inline-svg`,
},
{
  resolve: `gatsby-plugin-image`,
},
{
  resolve: `gatsby-plugin-manifest`,
  options: {
     // Details removed for privacy
    cache_busting_mode: 'none',
    crossOrigin: 'anonymous',
  },
},

// this (optional) plugin enables Progressive Web App + Offline functionality
// To learn more, visit: https://gatsby.dev/offline
{
  resolve: `gatsby-plugin-offline`,
},
// `gatsby-plugin-force-trailing-slashes`,
{
  resolve: 'gatsby-source-contentful',
  options: {
    spaceId: CONTENTFUL_SPACE_ID,
    accessToken: ACCESS_TOKEN,
  },
},
{
  resolve: 'gatsby-source-contentful',
  options: {
    spaceId: AIR_CONTENTFUL_SPACE_ID,
    accessToken: AIR_ACCESS_TOKEN,
  },
},
{
  resolve: `gatsby-transformer-remark`,
  options: {
    plugins: [
      {
        resolve: `gatsby-remark-embed-video`,
        options: {
          width: 560,
          height: 315,
          related: false,
          noIframeBorder: true,
        },
      },
      {
        resolve: `gatsby-remark-responsive-iframe`,
      },
      {
        resolve: `gatsby-remark-images-contentful`,
        options: {
          maxWidth: 800,
          withWebp: true,
          linkImagesToOriginal: false,
          sizeByPixelDensity: true,
        },
      },
      {
        resolve: `gatsby-remark-autolink-headers`,
        options: {
          icon: `<svg width="36" height="36" viewBox="0 0 36 36" fill="none" xmlns="http://www.w3.org/2000/svg"> <circle cx="18" cy="18" r="18" fill="white"/> <path fill-rule="evenodd" clip-rule="evenodd" d="M16 23C16 23.6 15.6 24 15 24H12C8.7 24 6 21.3 6 18C6 14.7 8.7 12 12 12H15C15.6 12 16 12.4 16 13C16 13.6 15.6 14 15 14H12C9.8 14 8 15.8 8 18C8 20.2 9.8 22 12 22H15C15.6 22 16 22.4 16 23ZM24 12H21C20.4 12 20 12.4 20 13C20 13.6 20.4 14 21 14H24C26.2 14 28 15.8 28 18C28 20.2 26.2 22 24 22H21C20.4 22 20 22.4 20 23C20 23.6 20.4 24 21 24H24C27.3 24 30 21.3 30 18C30 14.7 27.3 12 24 12ZM14 19C13.4 19 13 18.6 13 18C13 17.4 13.4 17 14 17H22C22.6 17 23 17.4 23 18C23 18.6 22.6 19 22 19H14Z" fill="#363E50"/> </svg>`,
          isIconAfterHeader: true,
          enableCustomId: true,
          elements: ['h1', 'h2', 'h3'],
          offsetY: 100,
        },
      },
      `gatsby-remark-prismjs`,
    ],
  },
},
{
  resolve: 'gatsby-plugin-preconnect',
  options: {
    domains: [
      'https://www.google.com',
      'https://googleads.g.doubleclick.net',
      'https://www.google-analytics.com',
      'https://www.googleadservices.com',
      'https://www.googletagmanager.com',
    ],
  },
},
{
  resolve: `gatsby-plugin-gdpr-cookies`,
  options: {
    googleTagManager: {
      trackingId: TAG_MANAGER_ID,
      cookieName: 'gatsby-gdpr-google-tagmanager',
      defaultDataLayer: { platform: 'gatsby' },
    },
    // only turn on when debugging
    // environments: ['production', 'development'],
  },
},
{
  resolve: `gatsby-plugin-algolia`,
  options: {
    enablePartialUpdates: true,
    appId: process.env.GATSBY_ALGOLIA_APP_ID,
    apiKey: process.env.ALGOLIA_ADMIN_KEY,
    queries,
    chunkSize: 10000, // default: 1000
  },
},
{
  resolve: `gatsby-plugin-netlify`,
  options: {
    headers: {
      '/**/*.html': [
        'cache-control: public',
        'cache-control: max-age=0',
        'cache-control: must-revalidate',
      ],
      '/page-data/*.json': [
        'cache-control: public',
        'cache-control: max-age=0',
        'cache-control: must-revalidate',
      ],
      '/app-data.json': [
        'cache-control: public',
        'cache-control: max-age=0',
        'cache-control: must-revalidate',
      ],
      '/static/*': [
        'cache-control: public',
        'cache-control: max-age=31536000',
        'cache-control: immutable',
      ],
      '/**/*.js': [
        'cache-control: public',
        'cache-control: max-age=3156000',
        'cache-control: immutable',
      ],
      '/**/*.css': [
        'cache-control: public',
        'cache-control: max-age=3156000',
        'cache-control: immutable',
      ],
      '/sw.js': [
        'cache-control: public',
        'cache-control: max-age=0',
        'cache-control: must-revalidate',
      ],
    },
  },
},       

Environment

Enter the following command in a terminal and copy/paste its output:

npx envinfo --system --binaries --browsers --npmPackages @netlify/plugin-gatsby

Screenshots

image

Can you submit a pull request?

No (don't know what the problem is)

Pull requests are welcome! If you would like to help us fix this bug, please
check our contributions guidelines.

@panzacoder panzacoder added the bug Something isn't working label Feb 3, 2022
@panzacoder
Copy link
Author

I just updated my node version to v16 (from v14) in netlify.toml and that seems to be making a positive impact so far.

I'm guessing this is related to this discussion: gatsbyjs/gatsby#34215

@ascorbic
Copy link
Member

ascorbic commented Feb 4, 2022

It certainly sounds like the same bug in parallel query running. You could try adding those env vars in the UI and see if it helps. Is it always the EPIPE error during image processing? Gatsby runs image processing in a separate worker thread, and what seems to be happening is that is that thread is crashing. Rather than the error from the worker beign surfaced, you're instead seeing the error from the parent failing to communicate with the worker.

@ascorbic
Copy link
Member

ascorbic commented Feb 4, 2022

The other thing that can cause an image processing thread to crash is a corrupt source image, but Gatsby is a lot better at catching those than it used to be, and it usually surfaces a more helpful error.

@panzacoder
Copy link
Author

It certainly sounds like the same bug in parallel query running. You could try adding those env vars in the UI and see if it helps. Is it always the EPIPE error during image processing? Gatsby runs image processing in a separate worker thread, and what seems to be happening is that is that thread is crashing. Rather than the error from the worker beign surfaced, you're instead seeing the error from the parent failing to communicate with the worker.

Every time it's EPIPE, and always at the image processing step. I looked around at recent publishes in Contentful and changes in the codebase, but there haven't been many changes lately.

Just check out how many failures I'm getting. It's also random, on when main built there were no code changes, just a retry deploy, same with the feature branch just above it. staging was also failing at the same time, and the code there was identical to main.

Screen Shot 2022-02-03 at 5 54 43 PM

I've been following/researching two topics related to this:

  • Issues with the parallel query running as we said (but I don't really understand what about the parallel thread is causing the error)
  • Gatsby v4 taking up far more memory than previous iterations (I think possibly because of the parallel query running?) and hitting the Netlify soft-limit of 3GB, however I've added GATSBY_CPU_COUNT=2 to my env with no affect, so not sure this is part of it.

Any initial thoughts on these two potential causes? Does it seem like they are related? Would you recommend downgrading to Gatsby v3? I can do an image audit and try to move all images that are in the repo to Contentful but it doesn't seem like that's the golden ticket to me, if little content has changed prior to upgrading to Gatsby v4.

@ascorbic
Copy link
Member

ascorbic commented Feb 4, 2022

Do you have a lot of images locally? I would certainly suggest moving them to Contentful if possible. The benefit there is that they don't need to be resized at build time, and can be served directly from Contentful. The Contentful integration with Gatsby image is very good.

@panzacoder
Copy link
Author

Yes there are around 100 images in the repo that are loaded using gatsby-plugin-image. I'll start there, thanks.

@panzacoder
Copy link
Author

Ok I've started the process of moving the images, but I was looking a little closer at a few things and have questions.

I ran a couple builds locally (I wanted to see if there was output in .cache/caches/gatsby-plugin-image/ after a build), and it failed at the same step as on Netlify... so I'm now thinking this conversation might belong better in the Gatsby PQR area.

Oddly, it fails on querying an image from Contenful at... w=40? I'm not sure why it would ever do that.

I'm thinking I need to take a closer look at how images are being pulled from contentful, especially when inlined in Markdown and transformed using gatsby-remark-images-contentful.

Here's the error:

Screen Shot 2022-02-04 at 6 22 58 PM

@ascorbic
Copy link
Member

ascorbic commented Feb 7, 2022

Ah, yes in that case I'd take this to the Gatsby issue. I wonder if it's a rate-limiting thing with Contentful.

@panzacoder
Copy link
Author

Hi @ascorbic thanks for talking with me over the last week. I have actually ultimately isolated my problems to the package gatsby-remark-images-contentful and the Contentful Long Textfield content type. It appears there is a step that happens in that process where the base64 of every image embedded in the Markdown. Since this happens as part of the queries it doesn't actually utilize gatsby-plugin-image for the processing and sourcing, and often makes the Run Queries in Workers step fail entirely.

That said, I would imagine other people who have this issue likely have some similar plugin that is making extraordinarily long / async requests at the query step.

Thanks for your help and I'm closing this ticket.

@ascorbic
Copy link
Member

ascorbic commented Feb 8, 2022

Thanks for letting me know! Glad you managed to track it down

@witcradg
Copy link

This same error can occur with Gatsby builds for projects that do not include gatsby-remark-images-contentful

@benlavalley
Copy link

This same error can occur with Gatsby builds for projects that do not include gatsby-remark-images-contentful

Same - I do not think this should be closed?

I am no longer able to deploy my Gatsby v4 app with Netlify at all.

A build that deployed fine on February 14th now no longer builds at all (same exact commit, just cant redeploy).

@ascorbic
Copy link
Member

ascorbic commented Mar 1, 2022

@benlavalley Can you share your build logs please

@benlavalley
Copy link

@ascorbic Yep! The good news is I also have my Netlify deploys working again after I locked Gatsby back to =v4.1.3 in my package.json. Here is a snippet of my build log I think you're looking for (I can share the entire thing if need be) - I was actually running gatsby@next here, I believe 4.9:

I also see no such entry for gatsby-plugin-sharp.IMAGE_PROCESSING on my Gatsby 4.1 version.

7:51:42 PM: success onPostBootstrap - 0.876s
7:51:42 PM: info bootstrap finished - 24.515s
7:51:42 PM: success write out requires - 0.016s
7:53:05 PM: success Building production JavaScript and CSS bundles - 83.376s
7:53:54 PM: success Building HTML renderer - 48.486s
7:53:54 PM: success Execute page configs - 0.182s
7:53:54 PM: success Caching Webpack compilations - 0.001s
7:54:20 PM: success run queries in workers - 25.667s - 93/93 3.62/s
7:55:10 PM: success Running gatsby-plugin-sharp.IMAGE_PROCESSING jobs - 209.669s - 102/102 0.49/s
7:55:10 PM: error UNHANDLED EXCEPTION write EPIPE
7:55:10 PM:
7:55:10 PM:
7:55:10 PM: Error: write EPIPE
7:55:10 PM:

@ascorbic
Copy link
Member

ascorbic commented Mar 1, 2022

This does seem to have been a memory issue related to parallel query processing, introduced in a recent version of Gatsby. What data source are you using for the images? Are they coming from a CMS?

@benlavalley
Copy link

This does seem to have been a memory issue related to parallel query processing, introduced in a recent version of Gatsby. What data source are you using for the images? Are they coming from a CMS?

Jut using flat files for my site content.

@ascorbic
Copy link
Member

ascorbic commented Mar 1, 2022

Are any of the source images particularly large?

@benlavalley
Copy link

Are any of the source images particularly large?

One was 14MB in size (just reduced to 2MB), a dozen or so are 1-2MB, and the rest are a few hundred KB.

@ascorbic
Copy link
Member

ascorbic commented Mar 1, 2022

Does reducing the 14MB one help?

@benlavalley
Copy link

Does reducing the 14MB one help?

It's a little tough to test only that change as I since added most of my static content back to my build and it's a bit of a pain to reduce it all again.

I did update to gatbsy@next (4.10 now) and it fails.

1:15:45 PM: success run queries in workers - 148.008s - 348/348 2.35/s
1:20:12 PM: success Running gatsby-plugin-sharp.IMAGE_PROCESSING jobs - 553.793s - 540/540 0.98/s
1:20:12 PM: error UNHANDLED EXCEPTION write EPIPE

Reverting back to 4.1 builds OK.

@jdahdah
Copy link

jdahdah commented Mar 10, 2022

Same issue here. Reverting to Gatsby 4.7.2 seems to have stabilized builds for now.

@ascorbic
Copy link
Member

Depending on your source plugins, you may like to try the new image CDN feature. That will defer image processing, which can save a lot of memory. https://www.netlify.com/blog/gatsby-image-cdn-on-netlify

Another option is to disable AVIF, which is very memory and CPU-intensive. You can change the defaults to ["auto", "webp"], which used to be the default. See the docs on how. Despite what that says, the default currently include avif too: https://www.gatsbyjs.com/plugins/gatsby-plugin-image/#customizing-the-default-options

@knupel
Copy link

knupel commented Apr 25, 2022

Same issue with Netlify and 28 mega of local picture. Previously the last deploy work fin with Gatsby 3:56:00 PM: > gatsby@4.5.3 postinstall /opt/build/repo/node_modules/gatsby

my current version is :

"dependencies": {
    "@emotion/react": "^11.9.0",
    "@material-ui/core": "^4.12.4",
    "@material-ui/icons": "^4.11.3",
    "axios": "^0.26.1",
    "gatsby": "^4.12.1",
    "gatsby-plugin-image": "^2.12.1",
    "gatsby-plugin-manifest": "^4.12.1",
    "gatsby-plugin-material-ui": "^4.1.0",
    "gatsby-plugin-offline": "^5.12.1",
    "gatsby-plugin-react-helmet": "^5.12.1",
    "gatsby-plugin-sass": "^5.12.1",
    "gatsby-plugin-sharp": "^4.12.1",
    "gatsby-plugin-web-font-loader": "^1.0.4",
    "gatsby-source-contentful": "^7.10.1",
    "gatsby-source-filesystem": "^4.12.1",
    "gatsby-source-mongodb": "^4.12.1",
    "gatsby-transformer-sharp": "^4.12.1",
    "p5": "^1.4.1",
    "prop-types": "^15.8.1",
    "react": "^18.0.0",
    "react-dom": "^18.0.0",
    "react-helmet": "^6.1.0",
    "sass": "^1.50.1"
  },

IF I understand well, I must remove my pics to have something light, is correct ? But what happen for the case where the people don't want remove pics, because for me 28Mg is not so heavy...

@witcradg
Copy link

I stopped having this error when I downgraded my node version to 16.
Environment settings:

NODE_OPTIONS --max-old-space-size=8192
NODE_VERSION 16.13.1
NPM_FLAGS --legacy-peer-deps

@knupel
Copy link

knupel commented Apr 26, 2022

I stopped having this error when I downgraded my node version to 16. Environment settings:

NODE_OPTIONS --max-old-space-size=8192 NODE_VERSION 16.13.1 NPM_FLAGS --legacy-peer-deps

is it not too dangerous to move from node v14.18.2 to node 16.13.1 I ask because I'm not comfortable with the internet jungle programmatic !

@witcradg
Copy link

witcradg commented Apr 26, 2022 via email

@knupel
Copy link

knupel commented Apr 27, 2022

NODE_OPTIONS --max-old-space-size=8192
NODE_VERSION 16.13.1
NPM_FLAGS --legacy-peer-deps

where you set that ? Because I update node v16.15.0 and it still doesn't work.
with this gatsby version :

  "dependencies": {
    "@emotion/react": "^11.9.0",
    "@material-ui/core": "^4.12.4",
    "@material-ui/icons": "^4.11.3",
    "axios": "^0.27.1",
    "gatsby": "^4.13.0",
    "gatsby-plugin-image": "^2.13.0",
    "gatsby-plugin-manifest": "^4.13.0",
    "gatsby-plugin-material-ui": "^4.1.0",
    "gatsby-plugin-offline": "^5.13.0",
    "gatsby-plugin-react-helmet": "^5.13.0",
    "gatsby-plugin-sass": "^5.13.0",
    "gatsby-plugin-sharp": "^4.13.0",
    "gatsby-plugin-web-font-loader": "^1.0.4",
    "gatsby-source-contentful": "^7.11.0",
    "gatsby-source-filesystem": "^4.13.0",
    "gatsby-source-mongodb": "^4.13.0",
    "gatsby-transformer-sharp": "^4.13.0",
    "p5": "^1.4.1",
    "prop-types": "^15.8.1",
    "react": "^18.1.0",
    "react-dom": "^18.1.0",
    "react-helmet": "^6.1.0",
    "sass": "^1.51.0"
  },

@witcradg
Copy link

witcradg commented Apr 28, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants