expressjs / serve-static

Serve static files
MIT License
1.4k stars 229 forks source link

EventEmitter memory leak #7

Closed 75lb closed 10 years ago

75lb commented 10 years ago

if you save this script as index.js and run it:

var connect = require('connect');
var serveStatic = require('serve-static');

var app = connect();

app.use(serveStatic('.'));
app.listen(8000);

then browse to http://localhost:8000/index.js and with the cache disabled refresh the page 9+ times you get this error:

(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
    at Socket.EventEmitter.addListener (events.js:160:15)
    at Socket.Readable.on (_stream_readable.js:688:33)
    at module.exports (/Users/Lloyd/Documents/75lb/tmp/node_modules/serve-static/node_modules/send/node_modules/finished/index.js:13:10)
    at SendStream.stream (/Users/Lloyd/Documents/75lb/tmp/node_modules/serve-static/node_modules/send/lib/send.js:526:3)
    at SendStream.send (/Users/Lloyd/Documents/75lb/tmp/node_modules/serve-static/node_modules/send/lib/send.js:470:8)
    at /Users/Lloyd/Documents/75lb/tmp/node_modules/serve-static/node_modules/send/lib/send.js:382:10
    at Object.oncomplete (fs.js:107:15)
75lb commented 10 years ago

v1.1.0 seems ok

dougwilson commented 10 years ago

So does this mean I can close it, since a new version does not have the issue?

75lb commented 10 years ago

v1.1.0 is an old version - i rolled back to it..

dougwilson commented 10 years ago

OK. So you are saying it worked in v1.1.0, but doesn't work now, I get it :)

dougwilson commented 10 years ago

The version after 1.1.0 is when the finished started to be used, which I see it is causing the emitter leak in the stack trace. I believe there is an open issue regarding that in that project.

75lb commented 10 years ago

exactly.. the issue is with releases 1.2.0 and 1.2.1.. 1.1.0 was the first working release i could find

75lb commented 10 years ago

yeah.. could something could be done in send to avoid the onFinish being repeatedly added?

dougwilson commented 10 years ago

could something could be done in send to avoid the onFinish being repeatedly added

It's only added once per request, as far as I know.

dougwilson commented 10 years ago

I'll try to figure out a fix for this today :)

75lb commented 10 years ago

good news :)

dougwilson commented 10 years ago

I have a fix in send, so I'll be working it down stream now :)

dougwilson commented 10 years ago

@75lb can you test the current version of master to see if the issue is gone for you? npm install expressjs/serve-static

75lb commented 10 years ago

boom shake the room! works fine for me.. thanks for the quick turnaround

dougwilson commented 10 years ago

Thanks. I'm releasing a patch version now that I have your confirmation :)

dougwilson commented 10 years ago

thanks for the quick turnaround

I have your example that allowed me to reproduce to thank :)