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

Cache persisting fails #36062

Closed
2 tasks done
and-who opened this issue Jul 5, 2022 · 5 comments
Closed
2 tasks done

Cache persisting fails #36062

and-who opened this issue Jul 5, 2022 · 5 comments
Labels
stale? Issue that may be closed soon due to the original author not responding any more. status: awaiting author response Additional information has been requested from the author type: bug An issue or pull request relating to a bug in Gatsby

Comments

@and-who
Copy link

and-who commented Jul 5, 2022

Preliminary Checks

Description

After a build is finished, gatsby tries to persist its Data in Cache Files.
This could Fail and result in the Following Error, e.g.:

warn Error persisting state: The value of "length" is out of range. It must be >= 0 && <= 2147483647. Received 2329483714

This Error Origins from the Gatsby Save State Funktion (v8.serialize())

report.warn(`Error persisting state: ${(err && err.message) || err}`)

The Problem is, that this Function uses a function to "guessSafeChunkSize"

export function guessSafeChunkSize(
values: Array<[string, IGatsbyNode]> | Array<[string, IGatsbyPage]>,
showMaxSizeWarning: boolean = false
): number {
// Pick a few random elements and measure their size then pick a chunk size
// ceiling based on the worst case. Each test takes time so there's trade-off.
// This attempts to prevent small sites with very large pages from OOMing.
// This heuristic could still fail if it randomly grabs the smallest nodes.
// TODO: test a few nodes per each type instead of from all nodes
const nodesToTest = 11 // Very arbitrary number
const valueCount = values.length
const step = Math.max(1, Math.ceil(valueCount / nodesToTest))
let maxSize = 0
for (let i = 0; i < valueCount; i += step) {
const size = v8.serialize(values[i]).length
maxSize = Math.max(size, maxSize)
}

and this Guess can be wrong which results in the Error mentioned above.
As one of your Developers mentioned "This heuristic could still fail if it randomly grabs the smallest nodes"
We are currently stuck with this Problem, because of our large number of nodes "step" will most likely be the same Value even when there are nodes added or removed. Therefore the values which are used to guess the Chunk Size are the same, therefore the guess will be "wrong" even after the next build.

There is a Experimental Flag "GATSBY_DISABLE_CACHE_PERSISTENCE", this is no Option, because we have a system for Incremental Builds, which relies on the Cache Data.

There was a PR which tried to make this Problem more controllable, sadly it got closed and not merged:
#29039

Reproduction Link

// This heuristic could still fail if it randomly grabs the smallest nodes.
// TODO: test a few nodes per each type instead of from all nodes
const nodesToTest = 11 // Very arbitrary number

Steps to Reproduce

Sadly this is hard to reproduce, you'll need a specific set of Nodes, so that the Heuristic picks bad Nodes to determine the Chunk Size.

This Problem occurs on our Production Environment, the Data there is multiple GB large.

Expected Result

The Caching persisting should be Fail save.
If this is not possible make the heuristic adjustable, e.g. Make it possible to change the Number of Nodes which get chosen,
or randomize the choosing of the Test Nodes a bit more, so subsequent builds wont fail.

And perhaps return an Error not a Warning, so we can detect corrupted Data.

Actual Result

The Persisting of the Cache Data fails for unlucky Data.
We have no way of controlling this.

Environment

OS: macOS 12.4
    CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
    Shell: 5.8 - /usr/local/bin/zsh
  Binaries:
    Node: 16.7.0 - /var/folders/p7/2kyvkfcs387899__10tmf9gh0000gp/T/yar
n--1657020894305-0.5687446657165263/node
    Yarn: 1.22.17 - /var/folders/p7/2kyvkfcs387899__10tmf9gh0000gp/T/ya
rn--1657020894305-0.5687446657165263/yarn
    npm: 7.20.3 - ~/.nvm/versions/node/v16.7.0/bin/npm
  Browsers:
    Chrome: 103.0.5060.114
    Firefox: 101.0.1
    Safari: 15.5

Config Flags

No response

@and-who and-who added the type: bug An issue or pull request relating to a bug in Gatsby label Jul 5, 2022
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Jul 5, 2022
@tyhopp
Copy link
Contributor

tyhopp commented Jul 6, 2022

Hi @and-who, thanks for the detailed issue description. What Gatsby version are you using? We no longer serialize nodes this way (they're now stored in lmdb), but pages still hit this code path.

@tyhopp tyhopp added status: awaiting author response Additional information has been requested from the author and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Jul 6, 2022
@and-who
Copy link
Author

and-who commented Jul 7, 2022

Currently we are using Gatsby 3
I was also thinking about upgrading, but i saw the same code in v4 so im not sure if this will fix it.
But this would be my next Step

@imjoshin
Copy link
Contributor

@and-who , while we can't promise upgrading to Gatsby 4 will fix the issue, it might see positive results. There were many changes to how the data is handled and the methods used to fetch data behind the scenes. Could you try an upgrade and see if the issue persists?

I agree that this method of caching our redux state should be revisited, nonetheless, just a matter of timing. If any fixes do come through, they will only be in Gatsby v4.

Thank you for reaching out, and thanks for using Gatsby! 💜

@github-actions
Copy link

github-actions bot commented Aug 2, 2022

Hiya!

This issue has gone quiet. Spooky quiet. 👻

We get a lot of issues, so we currently close issues after 60 days of inactivity. It’s been at least 20 days since the last update here.
If we missed this issue or if you want to keep it open, please reply here.
As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks for being a part of the Gatsby community! 💪💜

@github-actions github-actions bot added the stale? Issue that may be closed soon due to the original author not responding any more. label Aug 2, 2022
@and-who
Copy link
Author

and-who commented Aug 29, 2022

It took some Time because we have a large Project but we migrated to Gatsby4 on Prod now.
The Error did not pop up since then.

So for now it looks good.

If the Issue appears again I will come back to you.

Thanks

@and-who and-who closed this as completed Aug 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale? Issue that may be closed soon due to the original author not responding any more. status: awaiting author response Additional information has been requested from the author type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

No branches or pull requests

3 participants