mysql icon indicating copy to clipboard operation
mysql copied to clipboard

Pool Error

Open nyrsimon opened this issue 12 years ago • 5 comments

Hi

Am experiencing a very strange issue with connection pools. It seems everything is working fine most of the time. However if I wait several minutes and then access the webpage (which makes an ajax call which fires the query) then I get a weird handshake error:

query error:Error: Handshake inactivity timeout
Application has thrown an uncaught exception and is terminated:
Error: Handshake inactivity timeout
    at Handshake.sequence.on.on.on.on.on.self._connection._startTLS.err.code (D:\home\site\wwwroot\node_m
odules\mysql\lib\protocol\Protocol.js:153:17)
    at Handshake.emit (events.js:92:17)
    at Handshake._onTimeout (D:\home\site\wwwroot\node_modules\mysql\lib\protocol\sequences\Sequence.js:1
16:8)
    at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)
    --------------------
    at Protocol._enqueue (D:\home\site\wwwroot\node_modules\mysql\lib\protocol\Protocol.js:135:48)
    at Protocol.handshake (D:\home\site\wwwroot\node_modules\mysql\lib\protocol\Protocol.js:52:41)
    at PoolConnection.connect (D:\home\site\wwwroot\node_modules\mysql\lib\Connection.js:108:18)
    at Pool.getConnection (D:\home\site\wwwroot\node_modules\mysql\lib\Pool.js:42:23)
    at Pool.releaseConnection (D:\home\site\wwwroot\node_modules\mysql\lib\Pool.js:123:10)
    at Pool._removeConnection (D:\home\site\wwwroot\node_modules\mysql\lib\Pool.js:216:8)
    at Ping._callback (D:\home\site\wwwroot\node_modules\mysql\lib\Pool.js:87:10)
    at Ping.Sequence.end (D:\home\site\wwwroot\node_modules\mysql\lib\protocol\sequences\Sequence.js:96:2
4)
    at D:\home\site\wwwroot\node_modules\mysql\lib\protocol\Protocol.js:367:16
    at Array.forEach (native)

It looks like something is timing out. Is it possible I am not releasing something (have checked all my code and can't see that).

I can visit the page hundreds of times and it will work - it seems to only cause this problem after several minutes of inactivity.

Any help is VERY much appreciated!

Thanks Simon

nyrsimon avatar Aug 27 '14 19:08 nyrsimon

So Handshake inactivity timeout is a new thing where the handshake between your server and the MySQL server actually has a timeout (before I never did). The timeout defaults to 10 seconds. It's possible your MySQL server or network may periodically be taking longer to respond. First, I would recommend trying to raise the timeout to see if that helps, because it's possible you simply need a longer timeout for your setup.

To change the timeout:

var pool = mysql.createPool({
  acquireTimeout: 30000 // 30s
})

dougwilson avatar Aug 27 '14 19:08 dougwilson

Thanks for the swift response - will try it out and let you know. I am using Azure, with nodejs on one machine and mysql on another, I wonder if one goes into a 'sleep' mode...

Will let you know how it goes

Simon

nyrsimon avatar Aug 27 '14 19:08 nyrsimon

Ah, on Azure. This sounds like what you may be seeing, which could take your connection time just over the 10 second default: http://forums.mysql.com/read.php?38,568294,568294

dougwilson avatar Aug 27 '14 19:08 dougwilson

So I tried multiple configs including running node locally and connecting to the DB remotely. I was still getting weird timeouts. I think it was with the way azure puts machines to sleep (the database machine) when they are idle. I moved to AWS today and so far it seems much better - will monitor but I think we can close the issue, it doesn't seem like a software issue but my infrastructure! Thanks for all your help

nyrsimon avatar Sep 02 '14 21:09 nyrsimon

I faced the same issue. The node and the mysql services were running on the same instance on Azure and I kept getting this error every time. When I changed the db host to 'localhost' it started working. This is so weird.

neilunadkat avatar Feb 12 '15 11:02 neilunadkat