Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reconnect to mysql when disconnected... #32

Open
tvl83 opened this issue Jun 20, 2017 · 12 comments
Open

reconnect to mysql when disconnected... #32

tvl83 opened this issue Jun 20, 2017 · 12 comments

Comments

@tvl83
Copy link

tvl83 commented Jun 20, 2017

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

@uksparky
Copy link

uksparky commented Aug 3, 2017

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

@tvl83
Copy link
Author

tvl83 commented Aug 4, 2017

@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

@uksparky
Copy link

uksparky commented Aug 12, 2017 via email

@miumax
Copy link

miumax commented Jan 30, 2018

@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.

@a-k-macdonald
Copy link

@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.

@miumax
Copy link

miumax commented Jan 30, 2018

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

@a-k-macdonald
Copy link

@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.

@miumax
Copy link

miumax commented Jan 30, 2018

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

@miumax
Copy link

miumax commented Jan 31, 2018

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

@a-k-macdonald
Copy link

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

@rodrigogs
Copy link

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

@shubhamdixit863
Copy link

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

Were you able to solve the problem ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants