node.js - possible EventEmitter memory leak detected - nodejs v.0.10.4 - on centos -
i'm trying create simple static file server node.js, namely serve videos video/mp4 (content-type), download via http.
to note, files large (more 100mb)
tried using package node-serve recommended static file serving not serve purpose (and looks using blocking reads).
my custom code work, yet i'm getting memory leak each request, after 10-20 requests crashes process following error: fatal error: call_and_retry_2 allocation failed - process out of memory
each refresh increasing node.js's memory footprint around 200mb.
looked @ of answers here memory leaks node.js, none of answers solve issue, seems platform specific or combination... , not strictly code fault, have noted developers experience issue since version 0.6+ of node.js...
also saw posts claim happens express (https://npmjs.org/package/express)
the code used:
var fs = require('fs'); var http = require('http'); var mediapath = '/mypublicdir'; function error404(res) { res.writehead(404,{'content-type':'text/plain'}); res.end(); } function err(str) { console.log(str); } var server = http.createserver(function (req,res){ var filename,readstream; filename = mediapath+req.url if (fs.existssync(filename)) { readstream = fs.createreadstream(filename, { 'flags': 'r', 'mode': 0666, //'encoding': 'binary', 'buffersize': 8 * 1024 }); } else { return; } readstream.on('data',function(data){ res.write(data); }); readstream.on('open',function(data){ console.log('stream open'); res.writehead(200,{'content-type':contenttypeselector('video'), 'content-transfer-encoding' : 'binary', 'transfer-encoding' : 'chunked' }); }); readstream.on('error',function(e){ error404(res); err('stream read error',{request:collectrequestmeta(req),filename:filename,error:e}); }); readstream.on('end',function(data){ }); }); server.listen(8080);
the full warning each request:
(node) warning: possible eventemitter memory leak detected. 11 listeners added. use emitter.setmaxlisteners() increase limit. trace @ socket.eventemitter.addlistener (events.js:160:15) @ socket.readable.on (_stream_readable.js:653:33) @ socket.eventemitter.once (events.js:179:8) @ tcp.onread (net.js:527:26)
while writing this, i've found following issue: nodejs : how debug "eventemitter memory leak detected. 11 listeners added"
which states bug in nodejs core :(
strangely on windows machine, not happen. ideas other installing legacy version v0.8.23 appreciated..
i experienced same issue on node 0.10.4 (node.js app becomes unresponsive if reload multiple times in quick succession) - best solution upgrade 0.10.15 - bug has been fixed in newer releases.
Comments
Post a Comment