Closed Hubro closed 12 years ago
I do not think this is a bug. Node will only terminate itself when there is "nothing left to do." Since there is a open Socket connection (your connection stream to the MySQL server is still open), Node seems to "hang."
You should consider calling con.end()
like this:
//...
trans.query('UPDATE Streams SET live=0;');
trans.commit(function() {
con.end();
});
This will work also (in this case), but is not recommended:
//...
trans.query('UPDATE Streams SET live=0;');
trans.commit();
con.end();
In this case, the 'END' query is queued for execution immediately after your transaction, and if you had nested queries or something more complex like that, 'END' may be executed beforehand, killing your connection too soon. So, it's best to call end()
inside of your last query's callback function.
Please let me know if that helps. Thanks!
I had no idea the MySQL connection would keep node open. I've never had a problem with this before using mysql-queues though. Perhaps you should give people a heads-up in the documentation that this could happen. In any case, thanks a lot for the quick help! :-)
I agree -- I fell into this trap when I was using node-mysql, too. I think this is definitely more of a node-mysql "issue," so I'm gunna leave it up to those guys to include the heads-up in their documentation. ;)
This is my code
The application runs like it should, the transaction succeeded as far as MySQL is concerned, but the application never exits. If I remove commit, the commit is implied and I get a warning, and the application still hangs for ever. If I remove both commit and execute, the program runs fine and exits like it should (But the SQL is never executed, obviously). Removing just execute has no effect, even though one would think that the transaction queue wouldn't ever start in that case.
I've tried debugging the issue using node-inspector. When I pause the application during the post-execution eternal hang, the call stack just says
Have I done something wrong, or is this indeed a bug?
node-mysql version: 0.9.5 node-mysql-queues version: 0.3.3