tonistiigi / mega

THIS REPO IS NOT MAINTAINED. Unofficial Node.js SDK for Mega
http://tonistiigi.github.com/mega
117 stars 33 forks source link

Trying to make a steaming service #7

Open ddavid67 opened 11 years ago

ddavid67 commented 11 years ago

Hi. Excuse my bad english, I'm french.

I'm trying to make a streaming service with node and VLC web plugin.

var mega = require('mega');
var express = require('express');
var app = express();
var server = require('http').createServer(app);

server.listen(8000);
app.get('/stream/:hash!:key', stream);

function stream(req, res)
{
    var hash = req.param('hash');
    var key = req.param('key');
    var file = mega.file('https://mega.co.nz/#!'+hash+'!'+key)

    file.download().pipe(res);
}

I got some errors

(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:653:33)
    at Socket.EventEmitter.once (events.js:179:8)
    at TCP.onread (net.js:527:26)

TypeError: Cannot read property 'length' of undefined
    at Request._callback (/home/sites/megastream_nodejs/node_modules/mega/lib/api.js:54:13)
    at self.callback (/home/sites/megastream_nodejs/node_modules/mega/node_modules/request/main.js:122:22)
    at Request.EventEmitter.emit (events.js:95:17)
    at ClientRequest.self.clientErrorHandler (/home/sites/megastream_nodejs/node_modules/mega/node_modules/request/main.js:225:10)
    at ClientRequest.EventEmitter.emit (events.js:95:17)
    at CleartextStream.socketCloseListener (http.js:1475:9)
    at CleartextStream.EventEmitter.emit (events.js:117:20)
    at tls.js:616:10
    at process._tickCallback (node.js:415:13)

The streaming works. But after the first warning, my memory increase very fast, and when it reach 1GB (I have 4GB of ram), the script crash with the last error (TypeError: Cannot read property 'length' of undefined).

What can I do about it ?

tonistiigi commented 11 years ago

The error itself is easy to fix. It just didn't returned out on network error.

Heap increase/EventEmitter warning is strange. Can you gist a script that I can just run that leaks memory. I tried your code with a network bench but even with 10 concurrent downloads couldn't get the memory to go over 50MB. Thats on OSX with node 0.8.22 and 0.10.2.