Created
March 5, 2016 08:39
-
-
Save Chunlin-Li/20ca5aa62cafed15d31b to your computer and use it in GitHub Desktop.
reduplicate node-inspetor network agent bug: injection of network agent cause EventEmitter memory leak.
This file contains hidden or 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'; | |
// use node-debug to run client.js and observe the memory useage. | |
var http = require('http'); | |
var keepAliveAgent = new http.Agent({keepAlive: true, maxSockets: 500}); | |
var list = []; | |
for (var i = 0; i < 500; i++) { | |
list.push("hello world"); | |
} | |
var data = list.join(''); | |
list = null; | |
setInterval(function(){ | |
var result = {}; | |
var clientReq = http.request({ | |
host: '127.0.0.1', | |
port: 4444, | |
path: '/', | |
agent: keepAliveAgent, | |
headers: { | |
'Content-Length': data.length | |
} | |
}, function(resp) { | |
result['body'] = []; | |
resp.on('data', function(chunk){ | |
result['body'].push(chunk); | |
}); | |
resp.on('end', function(){ | |
result['body'] = Buffer.concat(result['body']); | |
}) | |
}); | |
clientReq.end(data); | |
clientReq.on('error', function(err){ | |
console.error('error ', err, err.stack); | |
}) | |
}, 100); | |
setInterval(function(){ | |
console.log('## MEM ', process.memoryUsage()); | |
}, 1000); |
This file contains hidden or 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'; | |
// use node to run server.js as normal. | |
var http = require('http'); | |
var list = []; | |
for (var i = 0; i < 500; i++) { | |
list.push("node-inspector/node-inspector") | |
} | |
var data = list.join(''); | |
list = null; | |
var server = http.createServer(function(req, res){ | |
var body = []; | |
req.on('data', function(chunk){ | |
body.push(chunk); | |
}); | |
req.on('end', function(){ | |
body = Buffer.concat(body); | |
setTimeout(function(){ | |
res.writeHead(200, {'Content-Length': data.length}, 'OK'); | |
res.write(data); | |
res.end(); | |
}, 100); | |
}); | |
}); | |
server.listen(4444); | |
setInterval(function(){ | |
console.log('## MEM ', process.memoryUsage()); | |
}, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment