-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Description
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
- When there is a connection issue (closed connection) during a query execution, the connection does not get removed from the pool and continues to be used, causing all queries executed after to fail with connection is closed error. The only way to recover from the issue is to restart the app. Note this does not happen on mysql dialect, only on Mysql2 dialect.
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)
const knex = require('knex')({
client: 'mysql2',
connection: {
host : '127.0.0.1',
port : 3306,
user : 'your_database_user',
password : 'your_database_password',
database : 'myapp_test'
},
pool: { min: 0, max: 7 }
});
const main = async function()
{
try {
await knex.raw("select sleep(100)");
// !! Manually KILL Connection from MYSQL to simulate connection error => KILL <pid>
} catch(err) {
console.log(err);
}
// all queries from now on will return error when reusing the same connection in the pool
try {
await knex.raw("select 1");
} catch(err) {
console.log(err);
}
process.exit();
}
main();
Metadata
Metadata
Assignees
Labels
No labels