Long chain promise => Out of memory
See original GitHub issueBluebird 3.3.4 and node v5.10.1.
I’m not sure if this is a bug or an expected behaviour that the earlier resolved promised in a chain doesn’t get collected up in GC. This might even be a node problem.
var Promise = require('bluebird')
function add(x){
return x+1
}
var a = Promise.resolve(0)
for(var i=0;i<10e8;i++){
a = a.then(add)
}
node screams with message like this
<--- Last few GCs --->
7440 ms: Scavenge 1413.8 (1458.1) -> 1413.8 (1458.1) MB, 24.1 / 0 ms (+ 0.9 ms in 1 steps since last GC) [allocation failure] [incremental marking delaying mark-sweep].
8138 ms: Mark-sweep 1413.8 (1458.1) -> 1413.8 (1458.1) MB, 698.2 / 0 ms (+ 0.9 ms in 1 steps since start of marking, biggest step 0.9 ms) [last resort gc].
8829 ms: Mark-sweep 1413.8 (1458.1) -> 1413.8 (1458.1) MB, 691.4 / 0 ms [last resort gc].
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0x3d33367e3ac1 <JS Object>
1: _then [xxx/node_modules/bluebird/js/release/promise.js:~217] [pc=0x1df6cf8b05d6] (this=0x35cfdd004101 <a Promise with map 0x1c4d6bb33c21>,didFulfill=0x2597f0bb95a9 <JS Function add (SharedFunctionInfo 0x2597f0b4ae79)>,didReject=0x3d3336704189 <undefined>,_=0x3d3336704189 <undefined>,receiver=0x3d3336704189 <undefined>,internalData=0x3d...
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory
Abort trap: 6
I know I could use each and such. But, the specific problem I’m trying to solve will involve stream of random data which I do not want to store the entire thing in a memory which will need to put in to db.
Is there a way to get around this?
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
JavaScript Promise Chaining Memory Leak Pattern - Cribl
In this post we'll walk through a memory leak pattern we recently encountered when using Javascript Promises.
Read more >How do you know when an indefinitely long promise chain ...
I'm being told that a "good" promise implementation would not cause accumulating memory from an indefinitely growing promise chain.
Read more >chain of never resolved promises create memory leaks #179
If we build a long/infinite promise chain gradually without the recursive code pattern, and only keep reference to the tail of the chain,...
Read more >Introduction - Alexandru Nedelcu
But It Does Unlimited Chaining of Promises; 3. ... This piece of code will leak memory and eventually crash your Node.js process or...
Read more >Using promises - JavaScript - MDN Web Docs
With this pattern, you can create longer chains of processing, where each promise represents the completion of one asynchronous step in the ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
No nextTick doesn’t mean the callbacks are called, only the callback being called means the callback has been called. setImmediate scheduler is used in node so the same code probably works with a setTimeout rather than nextTick which won’t allow setImmediate to trigger.
For unsuspecting passerby in the future, this one works (very slowly), but it works. (One could group it so setImmediate doesn’t get called so often)