1

I am using mysql in Node.js 6.7.0 to get data from database

connection.query('SELECT * FROM table', function(err, results){

    if(err){
        console.log('Error while performing the database query:', err);
        return;
    }else{
        console.log('Query results:', results);
    }

});

I was normally opening the page (which was previously working) when I got an error:

Error while performing the database query: Error: Handshake inactivity timeout

The server didn't stop running, I refreshed the page and everything is ok...

It never happened before, what does this mean?

This is the full error that I got in the log:

Error while performing the database query: { Error: Handshake inactivity timeout
    at Handshake.<anonymous> (/Users/johndoe/myproject/node_modules/mysql/lib/protocol/Protocol.js:160:17)
    at emitNone (events.js:86:13)
    at Handshake.emit (events.js:185:7)
    at Handshake._onTimeout (/Users/johndoe/myproject/node_modules/mysql/lib/protocol/sequences/Sequence.js:127:8)
    at tryOnTimeout (timers.js:232:11)
    at Timer.listOnTimeout (timers.js:202:5)
    --------------------
    at Protocol._enqueue (/Users/johndoe/myproject/node_modules/mysql/lib/protocol/Protocol.js:141:48)
    at Protocol.handshake (/Users/johndoe/myproject/node_modules/mysql/lib/protocol/Protocol.js:52:41)
    at PoolConnection.connect (/Users/johndoe/myproject/node_modules/mysql/lib/Connection.js:136:18)
    at Pool.getConnection (/Users/johndoe/myproject/node_modules/mysql/lib/Pool.js:48:16)
    at Pool.query (/Users/johndoe/myproject/node_modules/mysql/lib/Pool.js:200:8)
    at /Users/johndoe/myproject/myscript.js:92:13
    at Layer.handle [as handle_request] (/Users/johndoe/myproject/node_modules/express/lib/router/layer.js:95:5)
    at next (/Users/johndoe/myproject/node_modules/express/lib/router/route.js:131:13)
    at Route.dispatch (/Users/johndoe/myproject/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/Users/johndoe/myproject/node_modules/express/lib/router/layer.js:95:5)
  code: 'PROTOCOL_SEQUENCE_TIMEOUT',
  fatal: true,
  timeout: 10000 }
neoDev
  • 2,879
  • 3
  • 33
  • 66
  • Sounds like your mysql server was too busy to accept an incoming connection. – Sammitch Dec 20 '16 at 01:56
  • 1
    You'll also want to be careful when having an `else` clause on a negated condition. That's a double negative: If *not not errors*. Removing the negation and reversing the blocks makes this more concise. The `if (err) { ...; return }` pattern usually keeps things tidy and by forcing an early `return` the rest of your code isn't indented as much. That's important when you're nesting callbacks where every level adds more confusion. – tadman Dec 20 '16 at 01:58
  • @tadman thank you for the tip, I edited it for posterity – neoDev Dec 20 '16 at 02:10
  • Getting better, but note that if you `return` the `else` condition is irrelevant. It will only happen if the `if` clause didn't fire, obviously, so you can remove it and just leave the rest of the code as-is. Keeps it minimal and orderly. – tadman Dec 20 '16 at 03:57
  • Are you sure your connection is active? Sometimes MySQL ditches inactive connections after a period of time, like an hour or so, and if you use a stale connection you can get errors like this. – tadman Dec 20 '16 at 03:58
  • https://github.com/mysqljs/mysql/issues/1239 – Adiii Dec 20 '16 at 05:58
  • https://stackoverflow.com/questions/35553432/error-handshake-inactivity-timeout-in-node-js-mysql-module/37054703#37054703 – Nick Kotenberg Jul 22 '19 at 16:10

0 Answers0