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
MYSQL2 Dialect - Connection not disposed after a connection error during query execution #4794
Comments
@davidf84 This looks like what I've been running into (let me know if you think this issue is different). While debugging I've noticed that the validateConnection function does not check for the _protocolError property. See: knex/lib/dialects/mysql2/index.js Lines 17 to 23 in fdad316
I've been able to fix it by replacing the function at runtime with something like the following:
While googling I came across the code that sequelize was using and they seem to be doing this, as well as checking _closing and stream.destroyed. See: https://github.com/sequelize/sequelize/blob/9f950cbcbdd659d559496b77c40e0f827b108561/lib/dialects/mysql/connection-manager.js#L141-L148 |
Hi @christianjank, yes that is the same issue and that solves it. At least we have a temporary fix until this is fixed in the library. Thanks for your help. |
@davidf84 Would you consider sending PR for this issue? |
@christianjank thanks for the solution, it's an easy fix.
I was just on it when you send your message. |
Fix released in 0.95.14 |
Environment
Knex version: 0.21.21 (same issue on 0.95.12)
Database + version: MYSQL 5.7
OS: Tested on Windows 10 and Linux Ubuntu 20.04.2
Bug
MYSQL2 does not emit an error event, when there is a connection issue while executing a query, but returns a fatal=true property in the exception. The dialect should handle this as a fatal error and set the __knex__disposed ?
Error: Can't add new command when connection is in closed state
Example Code (needs a mysql server)
The text was updated successfully, but these errors were encountered: