0

I'm using nodejs with node-mysql to connect to a mysql database. I'm using pool.query to call a stored procedure in the database. This particular one takes quite a while to run. I receive this error

Error: Connection lost: The server closed the connection.

After exactly 10 minutes of waiting for the query to complete. The server is hanging up on me (because the connection has been idle for too long?), but I can't find any mysql variable that would be causing a disconnect after 10 minutes. I'm sure I've just got something misconfigured, but can't track down what that might be.

Paul Milham
  • 526
  • 5
  • 13
  • this is not a node.js configuration, it is one mysql configuration http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_wait_timeout check the SO http://stackoverflow.com/questions/26533936/node-js-mysql-connection-via-a-singleton – fmodos Nov 06 '14 at 18:03
  • wait_timeout on my mysql server is the default 28800 (which is 8 hours) Is there another variable that overrides this one that I'm missing or something? – Paul Milham Nov 06 '14 at 18:38
  • So this issue seems to be directly related to using pool.query. I changed my code to do pool.getConnection first, then ran the query on the connection instead of the pool and the 10 minute disconnect does not occur. I've filed the issue here: https://github.com/felixge/node-mysql/issues/942 – Paul Milham Nov 07 '14 at 17:44

1 Answers1

0
setInterval(function () {
    db.query('SELECT 1');
}, 300000);

excute the query for every 5 minutes keeps the connection live so it might solve your problem

Lokesh G
  • 831
  • 11
  • 19