3

I am trying to use the nodejs-mysql module from felixge. What I need to do is to make an one off query, get the result and end the connection.

As you can see bellow I set up my connection, query and on results I try to end the connection. Now the problem is although I send a ComQuitPacket it doesn't disconnect properly and waits till the database connection times out. Btw the data are received correctly and fine.

I run a SHOW FULL PROCESSLIST on the database but there is no connection being shown AFTER I receive the data.

Am I ending the connection in a wrong way? I also tried removing the callback and not ending the response but nothing.

There is ticket which is now closed in github https://github.com/felixge/node-mysql/issues/1223

By the way I am using ClearDB MySQL :: Database from Heroku! Also I am using node v5.4.0

var connection = mysql.createConnection({
 debug: true,
 host: enhancedWidgetModel.dataSource.mysql.host,
 user: enhancedWidgetModel.dataSource.mysql.username,
 password: enhancedWidgetModel.dataSource.mysql.password,
 database: enhancedWidgetModel.dataSource.mysql.database
})

  connection.query(enhancedWidgetModel.query, function (err, rows, fields) {
    connection.end(function (err) {
      if (err) {
        console.log(err)
      } else {
        console.log('ended')
      }
    })
    if (err) {
      console.log(err)
      callback({
        data: null,
        msg: 'error',
        code: 'error'
      })
    } else if (rows) {
      callback({
        data: rows,
        msg: 'acknowledged',
        code: 'success'
      })
    }
  })


<-- EofPacket
EofPacket {
  fieldCount: 254,
  warningCount: 0,
  serverStatus: 34,
  protocol41: true }

--> ComQuitPacket
ComQuitPacket { command: 1 }

{ [Error: Quit inactivity timeout]
  code: 'PROTOCOL_SEQUENCE_TIMEOUT',
  fatal: true,
  timeout: 30000 }

Raised an issue with the github repo: https://github.com/felixge/node-mysql/issues/1334

czioutas
  • 1,032
  • 2
  • 11
  • 37
  • Answer from ClearDB "We have noted some issues with nodeJs in this respect. Unfortunately we have no recommended fix except to make sure you're using the most recent version of the package. I'm sorry I can't be more helpful." – czioutas Jul 08 '16 at 11:29

0 Answers0