-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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 for async/await with es6 target #36056
Comments
Are you sure the memory is leaking, and you're not just running out of memory? As you're not awaiting any call you're creating 10.000.000 async calls simultaneously, and the polyfill requires a lot more memory than the natively supported version. |
Apologies, the example should contain an |
We were seeing this in production for our Apollo GraphQL implementation and for Node 12, believe the root cause is nodejs/node#30753 which will be fixed in 12.15. |
I have verified that @matthemsteger is correct. This was a bug in v8 which has since been fixed: https://bugs.chromium.org/p/v8/issues/detail?id=10031. I've verified this in v8 8.1.310: // index.js
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
class AsyncDoer {
doIt() {
return __awaiter(this, void 0, void 0, function* () {
return null;
});
}
}
const run = () => __awaiter(this, void 0, void 0, function* () {
for (let index = 0; index < 10000000; index++) {
const doer = new AsyncDoer();
yield doer.doIt();
}
print("done");
});
run(); > v8 -v
V8 version 8.1.310
> v8 index.js
done |
This is an annoying problem that i've been searching for days to find the solution, tsconfig.json use option {target:'es6'} ,then the generated code use __awaiter which implemented through es6 Generator instand of 'async & await',so this problem will come out if you use node 12 then use TypeScript to compile a async/await codes to es6,that's destructive. the solution of mine is set target to es7,then the problem is gone. |
When the supplied code is compiled with target es6 it results in a memory leak, however when the target is es2017 this is not the case.
TypeScript Version: 3.7.4
Node Version: 11.14.0
Search Terms:
memory leak
target
async
__awaiter
Code
when compiled with es6 target results in:
when compiled with es2017 target, results in:
Expected behavior:
When compiled with the following config:
The js output can be run to completion using the command
node --max-old-space-size=100
.Actual behavior:
The program crashes with an out of memory:
The text was updated successfully, but these errors were encountered: