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

longStackTraces memory issue #447

Closed
Volox opened this issue Jan 15, 2015 · 7 comments
Closed

longStackTraces memory issue #447

Volox opened this issue Jan 15, 2015 · 7 comments

Comments

@Volox
Copy link

@Volox Volox commented Jan 15, 2015

Hi,
i have a memory issue using Promise.longStackTraces(). I tried to create an "infite loop" for a crawler and noticed a huge memory usage for the application; i debugged the application and found a strange behaviour.

The following code illustrates the problem:

var Promise = require( 'bluebird' );
Promise.longStackTraces();
var SIZE=1024*1024;

function crawlLoop() {
  var arr = [];
  for( var i=0; i<SIZE; i++ ) {
    arr.push( {} );
  }
  return Promise.resolve( arr ).then( crawlLoop );
}

crawlLoop();

After a few tentatives i noticed that by removing Promise.longStackTraces() the problem was solved.
Another solution is to call setImmediate in the last then of the promise like:

return Promise.resolve( arr ).then( function() { setImmediate( crawlLoop ); } );

Can someone please explain me what is wrong with the code (a part for the infinite loop)?

My configuration:
node x64 0.11.13
Windows x64
Bluebird: 2.3.11

Thanks!

@petkaantonov
Copy link
Owner

@petkaantonov petkaantonov commented Jan 15, 2015

Can you use the latest version? The memory leak was fixed in 2.4.3 (But don't use that exact version, as it caused several regressions which were later fixed)

@janez87
Copy link

@janez87 janez87 commented Jan 15, 2015

Hi,
I can reproduce the problem with the latest (2.6.4) version.

node x64 0.10.28
osx 10.10

@Volox
Copy link
Author

@Volox Volox commented Jan 15, 2015

Just updated to 2.6.4 still same problem :(

@petkaantonov
Copy link
Owner

@petkaantonov petkaantonov commented Jan 15, 2015

I can fix the memory leak but the given code will still keep using maximum memory because it runs synchronously. However if you do someAsyncAction().then(crawlLoop) there is no memory issue. Is such fix fine?

@Volox
Copy link
Author

@Volox Volox commented Jan 15, 2015

I've got the same problem also using an async function like in the following code:

var Promise = require( 'bluebird' );
Promise.longStackTraces();

var SIZE=1024*1024;

var asyncFun = function() {
  return new Promise( function( res ) {
    setTimeout( function() {
      var arr = [];
      for( var i=0; i<SIZE; i++ ) {
        arr.push( {} );
      }
      return res( arr );
    }, 100 );
  } );
};

function crawlLoop() {
  return asyncFun()
  .then( crawlLoop );
  // .then( function() { setImmediate( crawlLoop ); } );
}

crawlLoop();
@petkaantonov
Copy link
Owner

@petkaantonov petkaantonov commented Jan 15, 2015

Fixed in 2.7.1, the original code stays at 100MB working set

@Volox
Copy link
Author

@Volox Volox commented Jan 15, 2015

Thanks!

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

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.