-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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? native Promise and complex arrow functions with Generators #4210
Comments
I think combined code, native Promise and arrow function, cause LEAK BUG. LEAK code 0: native Promise and arrow function expression without block statements. var fork = gen => new Promise((res, rej, cb) => (
cb = (err, val) => (
(val = err ? gen.throw(err) : gen.next(val)),
(val.done ? res(val.value) : val.value.then(val => cb(null, val), cb))
), cb()
)); NOT LEAK code 1: arrow function expression with block statements. var fork = gen => new Promise((res, rej) => {
var cb = (err, val) => {
try { val = err ? gen.throw(err) : gen.next(val); } catch (e) { rej(e); }
val.done ? res(val.value) : val.value.then(val => cb(null, val), cb);
}; cb();
}); or NOT LEAK code 2: do not use native Promise. npm "bluebord" or npm "promise-light". var Promise = require('bluebird');
// or
var Promise = require('promise-light'); or NOT LEAK code 3: use famous coroutine library, like npm "co". or miner npm "aa". var fork = require('co');
//
var fork = require('aa'); Why code 0 LEAK? |
I think your leakage has nothing to do with using statements or expressions. I reduced your code to a reproducible minimum with both versions - though I must admit I wasn't quite sure what the code tried to do. Both error out. Btw, in order to make it (not) work, I had to let .then not return cb anymore - not sure if that was important or not?
I believe you are experiencing a V8 Promise bug: The bug has been fixed recently in v8, but hasn't made its way into Node.js yet. In order to (temporary) fix the problem you can use another userland Promise implementation as you suggested:
PS: Is that a good idea to declare a variable in the function callback for the expression? Couldn't it possibly cause issues if the Promise constructor would extend the callback signature to a third parameter? Not like that they would ever do that, but hypothetically. |
Closing as it's not an actionable issue right now. |
Just checking in on the current state of this since it's been a year. Is this something that's actionable now? Has it already been resolved? Am I talking about this in the wrong place? |
As #4210 (comment) indicates the fix landed in V8 master last year so I think it should already landed in Node now. You can try to reproduce it. |
Memory Leak? native Promise and complex arrow functions with Generators.
node version: v0.12.9, v4.2.3, v5.1.1, v5.2.0 (x86, x64)
I tried Windows version. OS: Windows 10 (64bit), Windows 8.1 (64bit).
following source causes Error.
using native Promise cause Error.
but, other Promise implementation such as npm "bluebird" or npm "promise-light", looks good.
or arrow function with block statement looks good.
The text was updated successfully, but these errors were encountered: