Repository navigation
Description
This is a Bug Report
Description
Endless recursive file loading exceeds process memory limits.
When trying to remove the serverless.yml here:
https://github.com/Nordstrom/hello-retail/tree/master/web
With the command (STAGE is properly defined and references an existing stack):
../node_modules/.bin/sls remove -s $STAGE -v
- What went wrong?
<--- Last few GCs --->
[22378:0x102804600] 192582 ms: Mark-sweep 1484.5 (1567.0) -> 1484.5 (1567.0) MB, 2065.8 / 0.0 ms allocation failure GC in old space requested
[22378:0x102804600] 194638 ms: Mark-sweep 1484.5 (1567.0) -> 1484.4 (1536.0) MB, 2056.4 / 0.0 ms last resort gc
[22378:0x102804600] 196780 ms: Mark-sweep 1484.4 (1536.0) -> 1484.4 (1536.0) MB, 2141.0 / 0.0 ms last resort gc
<--- JS stacktrace --->
==== JS stack trace =========================================
2: arguments adaptor frame: 1->2
Security context: 0x90122ec0d31 <JS Object>
3: _settlePromiseFromHandler [<src-root>/hello-retail/node_modules/serverless/node_modules/bluebird/js/release/promise.js:~496] [pc=0x20e01cfbd1f3](this=0x2d4a7d8ea59 <a Promise with map 0x17140f73cc21>,handler=0x2d4a7d97671 <JS Function getValueFromSource.then.valueToPopulate (SharedFunctionInfo 0x2b325a77f011)>,receiver=0x90122e04311 <undefined>,val...
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
1: node::Abort() [~/.nvm/versions/node/v7.2.0/bin/node]
2: node::FatalException(v8::Isolate*, v8::Local<v8::Value>, v8::Local<v8::Message>) [~/.nvm/versions/node/v7.2.0/bin/node]
3: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [~/.nvm/versions/node/v7.2.0/bin/node]
4: v8::internal::Factory::NewByteArray(int, v8::internal::PretenureFlag) [~/.nvm/versions/node/v7.2.0/bin/node]
5: v8::internal::SourcePositionTableBuilder::ToSourcePositionTable(v8::internal::Isolate*, v8::internal::Handle<v8::internal::AbstractCode>) [~/.nvm/versions/node/v7.2.0/bin/node]
6: v8::internal::FullCodeGenerator::MakeCode(v8::internal::CompilationInfo*) [~/.nvm/versions/node/v7.2.0/bin/node]
7: v8::internal::(anonymous namespace)::GenerateUnoptimizedCode(v8::internal::CompilationInfo*) [~/.nvm/versions/node/v7.2.0/bin/node]
8: v8::internal::(anonymous namespace)::GetUnoptimizedCode(v8::internal::CompilationInfo*) [~/.nvm/versions/node/v7.2.0/bin/node]
9: v8::internal::Compiler::Compile(v8::internal::Handle<v8::internal::JSFunction>, v8::internal::Compiler::ClearExceptionFlag) [~/.nvm/versions/node/v7.2.0/bin/node]
10: v8::internal::Runtime_CompileLazy(int, v8::internal::Object**, v8::internal::Isolate*) [~/.nvm/versions/node/v7.2.0/bin/node]
11: 0x20e01ca063a7
12: 0x20e01ca0675a
13: 0x20e01ca07e55
14: 0x20e01cfbd1f3
15: 0x20e01cfe1eb4
Abort trap: 6
- What did you expect should have happened?
Expected: removal of stack
Downgrading to [email protected] allowed this to proceed as expected.
- What was the config you used?
- What stacktrace or error message from your provider did you see?
see above.
Additional Data
I suspect that this change may have introduced the new behavior but am not certain:
971a279#diff-b921cbcedd2151d24391fb39acb84adeR88
- Serverless Framework Version you're using: 1.13.2, 1.14.0
- Operating System: osx
- Stack Trace: see above
- Provider Error messages: n/a
Reacted by Antanas Brazenas, Mark Vayngrib, Andrew Munsell, Dean Shelton, Asaf Zamir, Justinas, Pavel-i-tel, Adnan Omarkhil, Jakub Chrzanowski, Bartholomew Elliott and 9 more
Reacted by Jonas Kemper and Alex Karolis
Activity
erikerikson commentedon Jun 7, 2017
This appears to be the result of changing the strategy of the variable resolution code so that it doesn't “replace in place” before recursively populating the resolved value (i.e. instead one should return the result and modify the original containing object before then trying to resolve the child).
I haven't tried but the following seems like it would reproduce:
~/config.yml
~/serverless.yml
~/serverless.ymlconfig.yml${self:custom.config.anotherVal}selfand finds that the custom.config value is${file(./config.yml)}: goto 2.entirely speculation.
pmuens commentedon Jun 7, 2017
Hey @erikerikson thanks for opening 👍
Yes, I think you're right. We've just merged a fix for such issues recently (will be included in v1.15).
Could you try it with the recent
masteror check again once we've publishedv1.15later today?#3709 is the PR with the fix for this.
Might also be related to #3627 and #3711.
HyperBrain commentedon Jun 7, 2017
In general, I think that a recursive approach for the variable substitution is not the best way (populateObject and populateProperty are calling themselves indirectly and each other). It would be better to implement that traversing with an iterative approach (breadth or depth first does not really matter).
With such an approach it is also easier to keep a map of visited objects locally.
erikerikson commentedon Jun 7, 2017
I tried this with the latest master and wasn't patient enough for it to blow up. Repetitive messages were written. Does not appear to be fixed in master.
pmuens commentedon Jun 8, 2017
Thanks for testing that out @erikerikson 👍
I think @HyperBrain has a valid point about recursion here. Seems like that's the root issue. Maybe we should change it to the propose BFS or DFS.
/cc @eahefnawy
erikerikson commentedon Jun 9, 2017
Maybe. The issue is a result of the ability to do things like
${self:custom.mySetting.${opt:stage}}. Breadth vs depth first is irrelevant in such a "rewind" and "reevaluate" case. It's simply that in a world allowing self-reference, that the referent must be replaced in place of the original reference before the original is processed further.HyperBrain commentedon Jun 10, 2017
@erikerikson Exactly. The inner references have to be resolved first as their values build up the outer references. So the dereferencing itself has to work with states that are stored on a stack in this case and the system would be rewinded to that state after the inner reference has been evaluated.
Additionally the newly generated references can cause circular references depending on the value of the inner reference(s). The algorithm should be able to detect that, i.e. the dynamically generated reference has to be put into the map of visited objects.
A point here is, that it is quite easy to detect these circular references and stop processing, but for the user it should show a kind of stack trace (i.e. the states that triggered a "rewind" or "reevaluate") to really show where the root of the circle is located.
iwllyu commentedon Jun 22, 2017
We're seeing a similar issue, the cause is a cyclic reference. I tried this with 1.16.0 running
sls deploy --acct dev --noDeployserverless.yml
replacing
${self:provider.vars.publicStreamName}with${self:provider.accounts.dev.publicStreamName}ordev_streamno longer produces the error18 remaining items
Eli-Goldberg commentedon Oct 7, 2017
Happens to me as well
fruffin commentedon Oct 17, 2017
Same problem here. That would be great to get this fix reviewed soon (I can confirm the fix works for my projects as well).
Workaround for now was to downgrade serverless back to a working version
Greenginer commentedon Oct 25, 2017
👍 for getting this fix out. This is starting to become a blocker to certain serverless deployments that are requiring difficult workarounds to utilize features that are available in later versions.
dashmug commentedon Jan 30, 2018
I'm getting this error randomly during
sls deploywith my project.I usually just restart the deploy and it's goes through the second time. This is probably caused by something else but I don't know where to start to investigate.
On successful builds, the output is like this:
On failed builds, the output is like this:
HyperBrain commentedon Jan 30, 2018
Hi @dashmug . Is the issue restricted to CodeBuild or does it happen in other environments too, and which loaders do you use in your project (e.g. TypeScript has some memory issues, where an issue already exists in the webpack repository). If the compile step scatters around in the Node heap, it might leave not enough memory afterwards.
dashmug commentedon Jan 30, 2018
@HyperBrain
I only build my projects through CodeBuild and that's where it happens randomly in around 1 out of 10 builds. I'll try to do some
sls deploysfrom my local to see if it happens locally.I do use Typescript with Webpack so this must be the reason. And this error hasn't happened for me in my non-Typescript Lambdas (though my non-typescript projects are relatively tiny compared to the typescript one).
Could the occurrence of this error increase with the number of Lambdas I have? I started having this failure right after I added a 5th Lambda function (each Lambda is an entry point in Webpack).
Are there known workarounds for this?
HyperBrain commentedon Jan 31, 2018
@dashmug You can check the comments in serverless-heaven/serverless-webpack#299. There has been a lengthy discussion of people facing the TypeScript memory problem and I remember there was some workaround that did the job.
alonsoir commentedon Jun 1, 2018
Hi, i am getting this exception with the getting-started example:
https://serverless.com/getting-started/
[email protected] /usr/local/lib/node_modules/npm
MacBook-Pro-Retina-de-Alonso:~ aironman$ npm version
{ npm: '5.0.3',
ares: '1.10.1-DEV',
cldr: '30.0.3',
http_parser: '2.7.0',
icu: '58.2',
modules: '57',
node: '8.1.4',
openssl: '1.0.2l',
tz: '2016j',
unicode: '9.0',
uv: '1.12.0',
v8: '5.8.283.41',
zlib: '1.2.11' }
https://pastebin.com/yb6ZTxjH
odykyi commentedon Feb 10, 2020
An update: it works when I set transpileOnly: true for ts-loader.
Berger92 commentedon Jul 27, 2020
@odykyi where did you set it? Could you show the whole thing please?
talaikis commentedon Jul 21, 2021
Mhm..., 32 Gb RAM, out of memory after removing serverlesss-plugin-include-packages.
pgrzesik commentedon Jul 21, 2021
Hello @talaikis 👋 Could you share more details about your case? What version of the Framework are you on? Any chance for a reproducible example that consumes a lot of memory? Thanks in advance 🙇