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

Comments

Projects
None yet
3 participants
@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

This comment has been minimized.

Show comment
Hide comment
@petkaantonov

petkaantonov Jan 15, 2015

Owner

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)

Owner

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

This comment has been minimized.

Show comment
Hide comment
@janez87

janez87 Jan 15, 2015

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

node x64 0.10.28
osx 10.10

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

This comment has been minimized.

Show comment
Hide comment
@Volox

Volox Jan 15, 2015

Just updated to 2.6.4 still same problem :(

Volox commented Jan 15, 2015

Just updated to 2.6.4 still same problem :(

@petkaantonov

This comment has been minimized.

Show comment
Hide comment
@petkaantonov

petkaantonov Jan 15, 2015

Owner

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?

Owner

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

This comment has been minimized.

Show comment
Hide comment
@Volox

Volox 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();

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

This comment has been minimized.

Show comment
Hide comment
@petkaantonov

petkaantonov Jan 15, 2015

Owner

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

Owner

petkaantonov commented Jan 15, 2015

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

@Volox

This comment has been minimized.

Show comment
Hide comment
@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