Closed conrad10781 closed 9 years ago
Here's a (not very good) solution I've been using.
connection.query(query, function(err,res) {
if (err) {
if (err.message.indexOf("connect") !== -1 || err.message.indexOf("gone away") !== -1) {
exports.init(global.database);
exports.query(query, callback);
@jaxbot , thanks for the response. I'd be curious to see if someone else has another approach. I've implemented a variation of yours in the meantime, that's just doing a SELECT NOW() every X period of time ( rather than on all the individual queries in the application ).
Has anyone explored the possibility of maybe having a disconnected event coming off the main object that could be used to quickly reconnect in one central location?
Connection is cheap, so you can open and close connection to TD every X requests or using timer.
I have a process that is intended to run for a long time. It's often processing several requests a second, but in some cases it can be > 1 day in between a request, which is resulting in a timeout of the connection.
Originally, when the longest time between requests was less than a day, I changed the MySQL wait_timeout value to 86400. I want to avoid making this number any bigger and am looking for a better way to handle this error.
I apologize if this is a duplicate of #163 , but I honestly couldn't understand the response in that issue, or at least how to modify it to resolve my problem.
In summary, is it possible to provide a snippet on how to deal with this issue ( once the problem happens ) or a way maybe to check before doing any queries if we have a valid connection ( before the problem )?