mysql-events icon indicating copy to clipboard operation
mysql-events copied to clipboard

reconnect to mysql when disconnected...

Open tvl83 opened this issue 8 years ago • 12 comments
trafficstars

Is there a way to detect if I am still connected to mysql and then reconnect if so?

I am using this library to update a firebase live db with information to use in an app. It seems around ~8-9 hours the updates just halt with no errors at all. I can only assume it is, for some reason, disconnecting from the mysqldb.

My initial thought is to run a cronjob every 7hr 55min or so to restart the nodejs app service.

I have a couple things that could be messed up by this even though the restart will be about 1 second long it can potentially cause issues every once in a while so I want to see about just reconnecting once it is disconnected.

Thank you

tvl83 avatar Jun 20 '17 20:06 tvl83

+1 for this, I also experience loss of insert events to the db, caused by loss of connection to the db.

uksparky avatar Aug 03 '17 23:08 uksparky

@uksparky while not the best resolution by any means I used a setInterval for 8 hours to close the connection and restart it and it's been reliable for almost a month now. I have no way of knowing what might be lost in that quick restart, unfortunately

tvl83 avatar Aug 04 '17 01:08 tvl83

Thanks for the workaround solution suggestion. Any chance of some example source so I ensure I wrap the right parts of code inside the setInterval. I presume your solution tears down the connections/listeners/etc and doesn't lead to excessive memory usage?

Cheers

On 4 Aug 2017 02:07, "Thomas Le" [email protected] wrote:

@uksparky https://github.com/uksparky while not the best resolution by any means I used a setInterval for 8 hours to close the connection and restart it and it's been reliable for almost a month now. I have no way of knowing what might be lost in that quick restart, unfortunately

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/spencerlambert/mysql-events/issues/32#issuecomment-320129433, or mute the thread https://github.com/notifications/unsubscribe-auth/ABrPrnSkuVca_BQdCCKp6YN7kE1hk7wHks5sUm6zgaJpZM4OAGxw .

uksparky avatar Aug 12 '17 03:08 uksparky

@tvl83 I also got the same issue. But no idea how you "close the connection and restart it" in the setInterval because the connection has done from the mysql-event . Can you please give some example ? that would be big help.

miumax avatar Jan 30 '18 07:01 miumax

@miumax I had this same issue for a while. The code would work nicely and then stop running with no visible sign. I realised, after a while, that I hadn't included the rotate event in the included events for my watcher. Once I set that it worked well.

a-k-macdonald avatar Jan 30 '18 09:01 a-k-macdonald

@a-k-macdonald Can you please give some code example about how to include that rotate event to watcher. That would be great.

miumax avatar Jan 30 '18 10:01 miumax

@miumax I set up my connection as below,

const settings = { includeEvents: ['rotate','tablemap', 'writerows', 'updaterows', 'deleterows'] } var mysqlEventWatcher = MySQLEvents(dsn,settings);

I take the defaults for everything else. I hope that helps.

a-k-macdonald avatar Jan 30 '18 11:01 a-k-macdonald

@a-k-macdonald Big thank, I'll do a try.

miumax avatar Jan 30 '18 11:01 miumax

@a-k-macdonald No luck. mysqlEventWatcher connection was disconnected after 7,8 hours.

miumax avatar Jan 31 '18 04:01 miumax

@miumax Sorry, I don't know what to suggest then.

a-k-macdonald avatar Jan 31 '18 09:01 a-k-macdonald

Using this lib you can pass a MySQL connection object to the constructor. So you're able to controll your connection out of the box.

https://github.com/rodrigogs/mysql-events

rodrigogs avatar Jun 27 '18 20:06 rodrigogs

@a-k-macdonald No luck. mysqlEventWatcher connection was disconnected after 7,8 hours.

Were you able to solve the problem ?

shubhamdixit863 avatar Aug 26 '20 19:08 shubhamdixit863