Skip to content

Instantly share code, notes, and snippets.

@rgrove
Created October 25, 2018 00:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rgrove/586d7f31dadea20ba06413833db11397 to your computer and use it in GitHub Desktop.
Save rgrove/586d7f31dadea20ba06413833db11397 to your computer and use it in GitHub Desktop.
Node 10 memory leak with domains & Express
'use strict';
const domain = require('domain');
const app = require('express')();
app.use((req, res, next) => {
let requestDomain = domain.create();
requestDomain.add(req);
requestDomain.on('error', next);
requestDomain.run(() => {
next();
});
});
app.get('/', (req, res) => {
req.cachedPromise = new Promise(resolve => {
let tenMebibyteString = 'a'.repeat(10 * 1024 * 1024);
resolve(tenMebibyteString);
});
res.send('hi');
});
app.listen(5000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment