gatsby: "invariant violation: inconsistent node counters detected" when upgrading to 4.8.0

Preliminary Checks

Description

When build in 4.8.0 process fails returning the attached error.

The error comes in queries with elemMatch filter. Everything normal in develop.

Thanks for any help.

Reproduction Link

https://github.com/pittica/site

Steps to Reproduce

  1. yarn install
  2. gatsby build

Expected Result

Expected: everything works fine.

Actual Result

ERROR #85901 GRAPHQL

There was an error in your GraphQL query:

Invariant violation: inconsistent node counters detected

1 | query CategoriesListTemplate($slug: String!, $limit: Int!, $skip: Int!, $locale: GraphCMS_Locale!, $stage: GraphCMS_Stage!) {

2 | posts: allGraphCmsPost( | ^ 3 | limit: $limit 4 | skip: $skip 5 | filter: {categories: {elemMatch: {slug: {eq: $slug}}}, stage: {eq: $stage}, locale: {eq: $locale}} 6 | sort: {fields: date, order: DESC} 7 | ) { 8 | nodes { 9 | id 10 | image { 11 | localFile { 12 | childImageSharp {

File path: D:/GitHub/pittica/site/src/templates/list/categories.jsx Url path: /categories/company Plugin: none

Error: Invariant violation: inconsistent node counters detected

  • indexing.ts:1145 intersectNodesByCounter [site]/[gatsby]/src/datastore/in-memory/indexing.ts:1145:15

  • run-fast-filters.ts:118 applyFastFilters [site]/[gatsby]/src/datastore/in-memory/run-fast-filters.ts:118:30

  • run-fast-filters.ts:382 convertAndApplyFastFilters [site]/[gatsby]/src/datastore/in-memory/run-fast-filters.ts:382:18

  • run-fast-filters.ts:308 runFastFiltersAndSort [site]/[gatsby]/src/datastore/in-memory/run-fast-filters.ts:308:18

  • lmdb-datastore.ts:205 Object.runQuery [site]/[gatsby]/src/datastore/lmdb/lmdb-datastore.ts:205:26

  • node-model.js:342 LocalNodeModel._query [site]/[gatsby]/src/schema/node-model.js:342:58

  • runMicrotasks

  • task_queues:96 processTicksAndRejections node:internal/process/task_queues:96:5

  • node-model.js:379 LocalNodeModel.findAll [site]/[gatsby]/src/schema/node-model.js:379:36

  • resolvers.ts:94 findManyPaginatedResolver [site]/[gatsby]/src/schema/resolvers.ts:94:20

  • async Promise.all

  • graphql-runner.ts:220 GraphQLRunner.query [site]/[gatsby]/src/query/graphql-runner.ts:220:14

  • query-runner.ts:135 queryRunner [site]/[gatsby]/src/query/query-runner.ts:135:14

ERROR #85928

An error occurred during parallel query running. Go here for troubleshooting tips: https://gatsby.dev/pqr-feedback

Error: Worker exited before finishing task

  • index.js:113 ChildProcess.<anonymous> [site]/[gatsby-worker]/dist/index.js:113:45

  • node:events:390 ChildProcess.emit node:events:390:28

  • child_process:290 Process.ChildProcess._handle.onexit node:internal/child_process:290:12

not finished run queries in workers - 2.029s

Environment

System:
    OS: Windows 10 10.0.22000
    CPU: (8) x64 Intel(R) Xeon(R) W-2225 CPU @ 4.10GHz
  Binaries:
    Node: 16.13.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.17 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 8.1.1 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 98.0.4758.102
    Edge: Spartan (44.22000.120.0), Chromium (98.0.1108.50)
  npmPackages:
    gatsby: ^4.8.0 => 4.8.0
    gatsby-cli: ^4.8.0 => 4.8.0
    gatsby-plugin-feed: ^4.8.0 => 4.8.0
    gatsby-plugin-gdpr-cookies: ^2.0.8 => 2.0.8
    gatsby-plugin-image: ^2.8.0 => 2.8.0
    gatsby-plugin-manifest: ^4.8.0 => 4.8.0
    gatsby-plugin-offline: ^5.8.0 => 5.8.0
    gatsby-plugin-preconnect: ^1.2.1 => 1.3.0
    gatsby-plugin-react-helmet: ^5.8.0 => 5.8.0
    gatsby-plugin-robots-txt: ^1.7.0 => 1.7.0
    gatsby-plugin-sass: ^5.8.0 => 5.8.0
    gatsby-plugin-sharp: ^4.8.0 => 4.8.0
    gatsby-plugin-sitemap: ^5.8.0 => 5.8.0
    gatsby-source-filesystem: ^4.8.0 => 4.8.0
    gatsby-source-graphcms: ^2.8.0 => 2.8.0
    gatsby-transformer-sharp: ^4.8.0 => 4.8.0
  npmGlobalPackages:
    gatsby-cli: 4.8.0

Config Flags

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 7
  • Comments: 25 (15 by maintainers)

Most upvoted comments

Should be fixed in gatsby@4.9.1

Finally produced a sample site that can reproduce this problem (via series of queries in gatsby-node) in https://github.com/pieh/i34910.

What seems so far it’s not related to single particular queries and rather to series of queries (execution order is important) where gatsby internal filter caches might lead to those errors. In a way I could reproduce is that there is a query that have some filter and then second query have same filter as previous - one more filter (that wasn’t seen before) and sort is aded on second query.

For now I opened https://github.com/gatsbyjs/gatsby/pull/35020 with failing test replicating reported error, actual fix for it is TBD.

Seems like 4.9.1 gives another problem of sorting not working. Still investigating, but thought it’s worth noting for those who hasn’t updated yet.

Add’l info

I clean built on 4.9.1 and got a problem. Either

  • on my local computer, the build would fail (due to some query not working)
  • on another computer, the sorting would be off (can’t debug this weird problem) Downgrading to ~4.7 fixes the problem.

gatsby develop on 4.9.1 presented no problem.

I don’t have time right now to create a reproduction though. Just in case this is helpful.

Same here. Removing a sort clause from the query solves the problem. Other queries on the same site which use sort do not cause the error to be thrown, and there are not obvious functional differences between them.

I will spend some time creating a minimal repro as well, but for now just thought I’d add a +1. Thanks to the maintainers and contributors for looking into this!

update

4.9.1 fixes the particular issue with same sort on differnt queries and different filters in one graphql in my case

deleted node_modules

did yarn install with “gatsby”: “^4.9.1” in my package.json

It requires environment variables/secrets to run the site that we don’t have 😕 Plus it’s not a minimal reproduction but the full blown site (that we discourage to share because it makes everything way more complicated)