-
Notifications
You must be signed in to change notification settings - Fork 2.5k
pool.getConnection(function (error, connection) not returning a connection #405
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
Comments
Do you have an error stack? What version are you using? |
I was logging errors on the pool.getconnection but the callback is never On Tuesday, March 5, 2013, Diogo Resende wrote:
|
Are you sure this isn't a bug of yours? Like for example calling |
Hi! EDIT: It seems that I did not properly clean up a query that failed because of inserting a duplicate value in the table. Now I have everything working again. |
It appears this error can occur because of forgetting to end a query retrieved from a pool. To be sure, you can set the To figure out where I'd forgotten to end a connection, I found adding this code to the first line of
I couldn't figure out a way to make a message print out whenever I ended a connection, however, despite trying several locations in Perhaps the library could use some kind of reference counting / garbage collection to produce an error when a connection object is not properly |
+1 to @RyanMarcus suggestion. Even with the |
How would one know when a connection should have been ended but wasn't? JavaScript does not expose a way to to when some code stops referencing a variable, and because the node.js environment is async, we cannot know when some code just forgot to call end on the connection or it is keeping it on purpose. If you send a PR that implements this somehow, that would be welcome. |
It's possible with https://github.com/TooTallNate/node-weak but I'm not sure that adding binary dependency worth here. IMO all pool & cluster pool code should be external to node-mysql ( I would happily reuse it in node-mysql2) and it should be possible to use custom pool like "automatic garbage collected node-weak powered" instead of default one |
@dougwilson Nobody's asking to do the impossible, but merely to improve the API to prevent programmer error. |
Sure, @statico , but I saw you seconded the reference counting. Were you meaning to second a different method? I'm certainly willing to improve it, but we just can't do reference counting. What method were you thinking of? Would using or adding some additional debug flag that printing when a connection was acquired and when a connection was released work (so you can try to guess it from the logs)? The main downside to this is of course you have to suspect this is the case in order to enable the flag in the first place... |
P.S. I like @sidorares suggestion of separating the pool from the main library. People could just use https://github.com/coopernurse/node-pool/ or potentially another pool that depended on a native module like https://github.com/TooTallNate/node-weak for reference counting (but we can't in the main library, because typically no Windows user can install native modules). |
Since the unexpected behavior here is caused when the pool is exhausted, I would have liked to have seen some notification as to when that happened. I'd like to see a lot more logging from this module in general (e.g., when a connection is dropped and reconnects), even if that logging were hidden behind a debug or verbose flag. |
I would actually suggest separation of query pre-processing as well ( with current implementations of pool & sqlstring require'd by default from external packages, no new behavior here and no extra setup steps ). Half of issues here are not related to core driver and sqlstring or pool related |
This would of course have to be hidden behind some kind of flag or maybe raise an event on the pool object (we don't want to write out to stdout/err randomly).
I like this idea. This is what we did to connect/express in expressjs, which is pretty sweet. |
One thing I noticed when looking at the code was the lack of events. I would be very happy if I could attach to more events (pool status, connection events, etc.) and log things myself that way. |
* README: document DSN system var quoting rules (mysqljs#405) Improve documentation of quoting rules for system var values in DSN. go-sql-driver/mysql#405 * Add myself to AUTHORS Fixes mysqljs#405
Hi,
Lately i've been experiencing an issue where pool.getConnection(function (error, connection) is not returning a function and is hanging any Express.js request i have that contains MySQL queries.
I've done debugging and tracked it back to this code.
The code i'm using is
var mysql = require('mysql'), sApp = null;module.exports = {
}
The text was updated successfully, but these errors were encountered: