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

memory leak #26

Closed
gsathya opened this issue Oct 6, 2016 · 3 comments
Closed

memory leak #26

gsathya opened this issue Oct 6, 2016 · 3 comments

Comments

@gsathya
Copy link

gsathya commented Oct 6, 2016

Test case --

let out;

async function longLoop() {
  for (let i = 0; i < 1000000; i++) await undefined;
  out = 1;
}

longLoop().then(() => console.log(1 === out));

Steps to reproduce --

  1. Run the above code through async-to-gen
  2. Run the generated code using node and set an upper bound on memory

Actual output --

➜   node --max-old-space-size=10  async-leak-gen.js                                                                        
<--- Last few GCs --->

     194 ms: Mark-sweep 16.0 (44.0) -> 15.9 (44.0) MB, 46.2 / 0.0 ms [allocation failure] [GC in old space requested].
     242 ms: Mark-sweep 15.9 (44.0) -> 15.9 (44.0) MB, 48.6 / 0.0 ms [allocation failure] [GC in old space requested].
     291 ms: Mark-sweep 15.9 (44.0) -> 15.7 (28.0) MB, 48.7 / 0.0 ms [last resort gc].
     344 ms: Mark-sweep 15.7 (28.0) -> 15.7 (28.0) MB, 52.5 / 0.0 ms [last resort gc].


<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 0x170d0accfb51 <JS Object>
    2: NewPromiseCapability(aka NewPromiseCapability) [native promise.js:175] [pc=0x379a595496a3] (this=0x170d0ac04381 <undefined>,O=0x170d0acc3059 <JS Function Promise (SharedFunctionInfo 0x170d0ac74f51)>)
    3: then [native promise.js:~215] [pc=0x379a59554f01] (this=0x1c8d0c9c9839 <a Promise with map 0x3b1fbab1b9b9>,z=0x1c8d0c9ca109 <
JS Function s (SharedFunctionInfo 0x6e897d5d7c1)>,A=0x1c8d...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [node]
 2: 0x10a08dc [node]
 3: v8::Utils::ReportApiFailure(char const*, char const*) [node]
 4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [node]
 5: v8::internal::Factory::NewOneByteInternalizedString(v8::internal::Vector<unsigned char const>, unsigned int) [node]
 6: v8::internal::AstRawStringInternalizationKey::AsHandle(v8::internal::Isolate*) [node]
 7: v8::internal::StringTable::LookupKey(v8::internal::Isolate*, v8::internal::HashTableKey*) [node]
 8: v8::internal::AstValueFactory::GetString(unsigned int, bool, v8::internal::Vector<unsigned char const>) [node]
 9: v8::internal::AstValueFactory::GetOneByteStringInternal(v8::internal::Vector<unsigned char const>) [node]
10: v8::internal::Scanner::CurrentSymbol(v8::internal::AstValueFactory*) [node]
11: v8::internal::ParserBase<v8::internal::ParserTraits>::ParseAndClassifyIdentifier(v8::internal::ExpressionClassifier<v8::internal
::ParserTraits>*, bool*) [node]
12: v8::internal::ParserBase<v8::internal::ParserTraits>::ParsePrimaryExpression(v8::internal::ExpressionClassifier<v8::internal::Pa
rserTraits>*, bool*) [node]
13: v8::internal::ParserBase<v8::internal::ParserTraits>::ParseMemberExpression(v8::internal::ExpressionClassifier<v8::internal::Par
serTraits>*, bool*) [node]
14: v8::internal::ParserBase<v8::internal::ParserTraits>::ParseMemberWithNewPrefixesExpression(v8::internal::ExpressionClassifier<v8
::internal::ParserTraits>*, bool*) [node]
15: v8::internal::ParserBase<v8::internal::ParserTraits>::ParseLeftHandSideExpression(v8::internal::ExpressionClassifier<v8::interna
l::ParserTraits>*, bool*) [node]
16: v8::internal::ParserBase<v8::internal::ParserTraits>::ParsePostfixExpression(v8::internal::ExpressionClassifier<v8::internal::Pa
... <snip>

Expected output --
Running non async-to-gen version with ToT v8

➜   ./out.gn/x64.release/d8 ~/code/scratch/async-leak.js --max-old-space-size 10
true
@leebyron
Copy link
Owner

leebyron commented Oct 7, 2016

Thanks for the report!

Any sense of where the root of this is?

@gsathya
Copy link
Author

gsathya commented Oct 7, 2016

@leebyron
Copy link
Owner

leebyron commented Oct 7, 2016

Nice catch! Yes, that indeed was the root cause - it looks like it was previously maintaining all prior Promises in the loop within a chain where that was not necessary or desirable.

The fixing commit uses your a slight variation of your test. I confirmed the same output on my machine before the fix and with the fix the test passes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants