Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closing DB connection #19

Open
jeffj opened this issue Feb 12, 2012 · 4 comments
Open

Closing DB connection #19

jeffj opened this issue Feb 12, 2012 · 4 comments

Comments

@jeffj
Copy link

jeffj commented Feb 12, 2012

How can I terminate the DB connection and all the instances of mongous functions?

@amark
Copy link
Owner

amark commented Feb 12, 2012

Huh, I hadn't even thought about it. Good point. I don't think you can do that now, ...
You can quickly add a handler in mongous.js, inside of mongous:

mongous.prototype.close = function(){ con.c.end() }

con.c in mongous.js is the require('net') object that does all the talking to MongoD.
This should work, I haven't tested it though, if it doesn't you might have to add a super wrapper for it (which isn't hard once you peek at the code, it is pretty short). But I will keep it in mind next time I update Mongous.
It should be pretty easy, though, to add. If you do, let me know and I'll merge your fork.

Then just set your mongous variable to null.

@jeffj
Copy link
Author

jeffj commented Feb 12, 2012

I added mongous.prototype.close = function(){ con.c.end() } at line 233 but I get the node error:

"node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
RangeError: Maximum call stack size exceeded"

@amark
Copy link
Owner

amark commented Feb 12, 2012

Hmm, I just tried it, and you are right, I get an error too. If I use con.c.destroy() I also get an error.
I know those are the methods that Node's net API says to use, and it isn't giving me really any debugging information (and I suck at debugging). If you could keep working on this, that would be nice. Elsewise I'll get around to it later (later = when I personally need it, which I don't foresee being any time soon).

It definitely should be implemented, though. Why do you need it, out of curiosity?

@jeffj
Copy link
Author

jeffj commented Feb 17, 2012

I want to use node for an program that is not a webserver. The application will access and upload information them the process will terminate. The connection to mongo is a prerequisite for this I think. My work around is to use a chron module in node so ending the .js script is no longer required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants