englercj / node-esl

FreeSWITCH ESL implementation for Node.js; implements the full Event Socket Library specified in: http://wiki.freeswitch.org/wiki/Esl
http://englercj.github.com/node-esl/
MIT License
170 stars 111 forks source link

Memory leak in `bgapi` #69

Closed franza closed 5 years ago

franza commented 6 years ago

Hello. I encountered this leak in v1.1.4 and v.1.1.9. As I understand it is because of the old version of eventemitter2 module.

https://github.com/englercj/node-esl/blob/cff8d9b42efbe7a38df717a9c8e193f183d0dbd2/lib/esl/Connection.js#L272

self.once('esl::event::BACKGROUND_JOB::' + jobid, function(evt) {
    removeFromFilter(function() {
        cb(evt);
    });
});

self.once here creates next object in self.listenerTree:

{
    esl: {
        event: {
            BACKGROUND_JOB: {
                [jobid]: { /* listener object */ }
            }
        }
    }
}

And when callback is executed it's still:

{
    esl: {
        event: {
            BACKGROUND_JOB: {
                [jobid]: { /* empty object */ }
            }
        }
    }
}

This produces a memory leak. It can be also reproduced here: https://gist.github.com/franza/02702238bf08dda42321e3f96ecb6251. I tried it with EventEmitter v1 and it fixed it.

It's worth to think about upgrading eventemitter2.

Ricardonacif commented 5 years ago

Can we consider this fixed?

franza commented 5 years ago

Sorry didn’t say it earlier. Yes that was fixed.