Closed brandonmp closed 6 years ago
found this comment & realized syntax was incorrect when increasing memory. Tried building w/this command:
node --max-old-space-size=8192 ./node_modules/.bin/gatsby develop
... but still hit 'heap out of memory' error (though took a lot longer).
I'm unable to replicate the error in a start kit w/ my JSON data sources, so I assume it has to be a confluence of factors, but a node process hitting 8GB of RAM on v 1.9.100, but building fine on v 1.9.9, has to be a memory leak somewhere under the hood in Gatsby, yea?
Where in the src can I look to understand what's happening here & how I might alter my configs to work around this? I want in on all the cool stuff added since 1.9.9 :/
This sounds bad :-( Sorry you're running into this but we appreciate you jumping to help find the fix. We definitely need performance tests in the future.
So best way to narrow down the problem is to use git bisect. Checkout Gatsby source and follow the contributing guide https://www.gatsbyjs.org/docs/how-to-contribute/ to run your code against source.
Then find the git commit id for your current version and start the bisect process to find out when things stopped working.
This isn't a perfect solution since it won't find out if one of our dependencies broke things but as long as the problem is in Gatsby's source, you should be able to track down where things broke fairly quickly.
I'm getting the same error when I try to run gatsby build
with about 500 JSON files with filesystem source and json transformer plugins. I'm currently using Gatsby 1.9.112. I'll see if I can figure out what's causing it.
EDIT: It works with Gatsby 1.9.9! With small changes though - I had to force the following versions:
"resolutions": {
"graphql": "0.10.5",
"relay-compiler": "1.3.0"
},
Otherwise I was getting some errors.
But now the build takes less than 10s:
$ rm -rf .cache/ public/ && gatsby develop
success delete html files from previous builds — 0.007 s
success open and validate gatsby-config.js — 0.004 s
success copy gatsby files — 0.021 s
success source and transform nodes — 1.859 s
success building schema — 0.930 s
success createLayouts — 0.019 s
success createPages — 1.215 s
success createPagesStatefully — 0.029 s
success extract queries from components — 0.174 s
success run graphql queries — 1.997 s
success write out page data — 0.017 s
success update schema — 0.954 s
info bootstrap finished - 9.122 s
I'll try to bump versions and see when it breaks.
@KyleAMathews actually is there a way to see what Gatsby is doing in the background? the --verbose
option is not helping as not much is being logged... As @szimek mentioned Gatsby gets stuck in the run graphql queries
step, namely Gatsby then becomes unresponsive (need to kill
it). Being able to have more information (e.g. --verbose all or something else) would be great. Do you have any idea how to process? I can have a look node debugger like you suggest here https://github.com/gatsbyjs/gatsby/issues/2866 but it might get complex :/
Update: running it with massive heap size unlocked Gatsby node --max-old-space-size=12000 ../../node_modules/gatsby/dist/bin/gatsby.js build
🤔
@KyleAMathews I looked into it and version 1.9.32 works, but 1.9.33 doesn't. It looks like the culprit is commit 7dd5f3b39b2231c91b7d0f410693267cf5575a40. Unfortunately, it added a bunch of recursive functions, so it's not that obvious yet which one(s) are causing it.
Running into this issue on my project also. In our context it only kicks in once we have over ~2000 pages on our site & we only require ~1200 for our Jan milestone so we're using as is for now. Will provide details/tests later once we can commit time & resource to fixing but just bumping to let you know others are affected
I'm also running into this issue when creating ~1700 pages. I've tried my best to optimize the queries on each page as much as possible, but I can't get the run graphql queries
step to complete
@robmccardle @benedfit There's already a PR that fixes this issue: https://github.com/gatsbyjs/gatsby/pull/2969. Please +1 it or sth to get it merged sooner :)
I've also created an issue (including very rough implementation) to not inline webpack chunk manifest here: https://github.com/gatsbyjs/gatsby/issues/2992 It can also be something that you might be interested in, if you're trying to use Gatsby with so many pages.
Would love to hear from y'all if things work better now. Sorry about the troubles you had in the past.
@KyleAMathews It works fine for us now with ~1K pages, so I think this issue can be closed now.
I noticed I was having performance issues with page creation using Semantic UI and as soon as I commented it out it started working. I was doing about 1800 pages.
I'm running into this issue (or something very similar) on my Gatsby-based blog.
Here's what I get when I run gatsby build
:
success delete html and css files from previous builds — 0.096 s
success open and validate gatsby-config.js — 0.007 s
success copy gatsby files — 0.018 s
success onPreBootstrap — 0.364 s
success source and transform nodes — 1.169 s
success building schema — 0.868 s
success createLayouts — 0.012 s
success createPages — 0.773 s
success createPagesStatefully — 0.044 s
success onPreExtractQueries — 0.000 s
success update schema — 1.525 s
success extract queries from components — 0.098 s
success run graphql queries — 8.712 s
success write out page data — 0.005 s
success write out redirect data — 0.001 s
success onPostBootstrap — 0.003 s
info bootstrap finished - 17.226 s
success Building CSS — 9.031 s
⠁ Building production JavaScript bundles
<--- Last few GCs --->
66181 ms: Mark-sweep 1181.4 (1431.9) -> 1180.8 (1437.9) MB, 103.0 / 0.0 ms [allocation failure] [GC in old space requested].
66283 ms: Mark-sweep 1180.8 (1437.9) -> 1184.4 (1437.9) MB, 102.3 / 0.0 ms [allocation failure] [GC in old space requested].
66395 ms: Mark-sweep 1184.4 (1437.9) -> 1199.4 (1405.9) MB, 112.2 / 0.0 ms [last resort gc].
66505 ms: Mark-sweep 1199.4 (1405.9) -> 1215.7 (1405.9) MB, 109.9 / 0.0 ms [last resort gc].
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0x2fc82293fa99 <JS Object>
1: stringify [native json.js:~176] [pc=0x14950bb93673] (this=0x2fc822946091 <a JSON with map 0xf4421a13b91>,E=0x200e2d17bfe1 <an Object with map 0x1a0781f9a4d1>,F=0x2fc822904241 <undefined>,S=0x2fc822904241 <undefined>)
2: arguments adaptor frame: 1->3
3: /* anonymous */ [/Users/stephennixon/Sites/blog2017-gatsby/node_modules/webpack/lib/SourceMapDevToolPlugin.js:147] [pc=0x14950c9c...
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
1: node::Abort() [/usr/local/bin/node]
2: node::FatalException(v8::Isolate*, v8::Local<v8::Value>, v8::Local<v8::Message>) [/usr/local/bin/node]
3: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/usr/local/bin/node]
4: v8::internal::Factory::NewRawTwoByteString(int, v8::internal::PretenureFlag) [/usr/local/bin/node]
5: v8::internal::String::SlowFlatten(v8::internal::Handle<v8::internal::ConsString>, v8::internal::PretenureFlag) [/usr/local/bin/node]
6: v8::internal::BasicJsonStringifier::SerializeString(v8::internal::Handle<v8::internal::String>) [/usr/local/bin/node]
7: v8::internal::BasicJsonStringifier::Result v8::internal::BasicJsonStringifier::Serialize_<false>(v8::internal::Handle<v8::internal::Object>, bool, v8::internal::Handle<v8::internal::Object>) [/usr/local/bin/node]
8: v8::internal::BasicJsonStringifier::SerializeJSArraySlow(v8::internal::Handle<v8::internal::JSArray>, unsigned int, unsigned int) [/usr/local/bin/node]
9: v8::internal::BasicJsonStringifier::Result v8::internal::BasicJsonStringifier::Serialize_<true>(v8::internal::Handle<v8::internal::Object>, bool, v8::internal::Handle<v8::internal::Object>) [/usr/local/bin/node]
10: v8::internal::BasicJsonStringifier::Result v8::internal::BasicJsonStringifier::Serialize_<false>(v8::internal::Handle<v8::internal::Object>, bool, v8::internal::Handle<v8::internal::Object>) [/usr/local/bin/node]
11: v8::internal::Runtime_BasicJSONStringify(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/local/bin/node]
12: 0x1495078060c7
13: 0x14950bb93673
14: 0x14950781c7d5
[3] 18077 abort gatsby build
Maybe this is due to my blog being fairly image-heavy? Still, I don't have that many posts, and I can't imagine I have the most image-heavy Gatsby site out there.
Strangely, I ran into this issue yesterday but got past it after updating to Gatsby 1.9.236. However, today I added a couple of images and a bit more text, and the issue is back.
@KyleAMathews I'm not sure I know how to use Git Bisect or to adjust the max-old-space-size
, both of which I see mentioned ... are either of these approaches things I should dig deeper into to troubleshoot this?
Thanks for any insight!
Strangely, I waited a few days and changed nothing ... and it now works.
In case anyone else comes across this and is in the same bind as me: if I do run into the problem again, I will likely try the suggested fix at https://stackoverflow.com/questions/26094420/fatal-error-call-and-retry-last-allocation-failed-process-out-of-memory/48895989#48895989
v2 uses a lot less memory as we don't try to render all html files at one 😅
For me this is still happening.
@KyleAMathews Could you tell me from what version this was fixed? Our project with "gatsby": "1.9.277" still has the same problem.
For anyone that may still be having issues, don't forget to try removing any lock files (package-lock.json
or yarn.lock
) and doing a fresh install with the most up to date version of gatsby. I spent a good amount of time trying to figure out why I was still getting this error even after updating gatsby and it turned out to be a stale lock file.
I've been putting off upgrading Gatsby b/c I kept getting a 'heap out of memory' error, but I decided today to track it down.
One of my
source-filesystem
sources creates 656 nodes (of typeconsultant
) from a JSON. the JSON is about 800kb.This is the output from running
yarn develop
:This happens both with and without the
--max-old-space-size=8192
flag.However, when I remove the
pageQuery
export from myconsultant
template, the build completes fine.I've tried pulling fields from the
pageQuery
to see if it was just one query that was doing it, but even with a trivial 1-field query, the crash happens.I can't imagine my 658 nodes is more than Gatsby can handle, but OTOH everything worked fine pre-upgrade (and still does on my Master branch), so just trying to narrow-down cause here.
Here's my versions before the upgrade:
And here's my versions post-upgrade: