Created
October 25, 2018 00:23
-
-
Save rgrove/586d7f31dadea20ba06413833db11397 to your computer and use it in GitHub Desktop.
Node 10 memory leak with domains & Express
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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