Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to destroy firebase ref in node

If I do this in node:

console.log('1');
console.log('2');

outputs:

1
2

And the process ends.

If I change it to this:

console.log('1');
var Firebase = require('firebase');
var ref = new Firebase('https://<some-base>.firebaseio.com/');
console.log('2');

outputs:

1
2

and the process continues.

I believe that this is because ref is keeping the process alive. I know that I can use process.exit but I would prefer to not do that. I actually don't want the process to exit anyway, I just want to make sure that I don't have a memory leak issue where my firebase ref lasts forever. Is there any way to destroy a firebase reference once I'm done with it?

like image 509
kentcdodds Avatar asked Dec 24 '14 20:12

kentcdodds


1 Answers

[Engineer at Firebase] Currently, instantiating the Firebase client with new Firebase(...) will create a long-lived persistent connection that keeps the Node.js process alive.

This is admittedly not ideal for a bunch of use cases, and we have some work to do here to ensure that the process exits cleanly and automatically when there are no outstanding Firebase listeners or pending writes to the server, but it's been medium / low priority. I'd expect a "fix" to be released by Q2 '15, hopefully Q1.

like image 173
Rob DiMarco Avatar answered Nov 14 '22 22:11

Rob DiMarco