Repository navigation
Closed
Labels
Description
What are you doing?
When using replication configuration with mysql dialect the whole nodejs process crashes when connection to database is lost.
To reproduce it locally turn DB on, start the code below and after one or more Success messages turn DB off.
const Sequelize = require('sequelize');
const sequelize = new Sequelize(<database>, <user>, <password>, {
replication: {
read: {host: 'localhost'},
write: {host: 'localhost'}
},
port: <port>,
dialect: 'mysql',
pool: {
max: 1,
min: 5
}
});
function performTest(msg, callback) {
sequelize
.query('SELECT VERSION();', {
type: Sequelize.QueryTypes.SELECT
})
.then(result => console.log('Success', result))
.catch(err => console.log('Failure', err))
.then(() => setTimeout(performTest, 1000));
}
performTest();What do you expect to happen?
Failure messages on the console as long as DB is down.
What is actually happening?
The whole process crashes with error:
<project_dir>\node_modules\sequelize\lib\dialects\abstract\connection-manager.js:166
return this.pool[mayBeConnection.queryType].destroy(mayBeConnection)
^
TypeError: Cannot read property 'destroy' of undefined
at Object.destroy (<project_dir>\node_modules\sequelize\lib\dialects\abstract\connection-manager.js:166:53)
at Connection.errorHandler (<project_dir>\node_modules\sequelize\lib\dialects\mysql\connection-manager.js:103:23)
at emitOne (events.js:116:13)
at Connection.emit (events.js:211:7)
at Connection._notifyError (<project_dir>\node_modules\mysql2\lib\connection.js:229:16)
at Socket.<anonymous> (<project_dir>\node_modules\mysql2\lib\connection.js:107:16)
at emitNone (events.js:111:20)
at Socket.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1056:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
Dialect: mysql
Dialect version: mysql2 v.1.5.3
Database version: 5.7.22, 5.6.40
Sequelize version: 4.37.10
Tested with latest release: Yes
Activity
borrys commentedon May 28, 2018
For what I found during debugging
abstract/connection-manager.json line 166 assumes thatmayBeConnection.queryTypeis set but it isundefined.I believe it is due to the fact that
mysql/connection-manager.jsregisters error handler on connection before the connection getsqueryTypeassigned (here or here)stale commentedon Aug 27, 2018
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment 🙂