Skip to content

Crash when connection to mySQL is lost #9487

Closed

Description

@borrys

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

  1. borrys commented on May 28, 2018

    @borrys
    Author

    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)

  2. stale commented on Aug 27, 2018

    @stale

    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 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions