Skip to content
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

Crash when connection to mySQL is lost #9487

Closed
borrys opened this issue May 28, 2018 · 2 comments
Closed

Crash when connection to mySQL is lost #9487

borrys opened this issue May 28, 2018 · 2 comments
Labels

Comments

@borrys
Copy link

borrys commented May 28, 2018

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

@borrys
Copy link
Author

borrys commented May 28, 2018

For what I found during debugging abstract/connection-manager.js on line 166 assumes that mayBeConnection.queryType is set but it is undefined.
I believe it is due to the fact that mysql/connection-manager.js registers error handler on connection before the connection gets queryType assigned (here or here)

@stale
Copy link

stale bot commented 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 🙂

@stale stale bot added the stale label Aug 27, 2018
@stale stale bot closed this as completed Sep 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants