Skip to content

Commit b7cac0a

Browse files
Sven HoexterFlorian Pelgrim
authored andcommitted
catch mysql connection errors and try to reconnect
To prevent the thread manager from killing us on a failed reconnect we can just catch the exception here and go on with another reconnect. That properly increases our internal counters and triggers the intendet error handling. Signed-off-by: Florian Pelgrim <florian.pelgrim@craneworks.de>
1 parent b3ce811 commit b7cac0a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

mysql_statsd/thread_mysql.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,11 @@ def configure(self, config_dict):
5555
return self.host, self.port, self.sleep_interval
5656

5757
def setup_connection(self):
58-
self.connection = mdb.connect(host=self.host, user=self.username, port=self.port, passwd=self.password)
59-
return self.connection
58+
try:
59+
self.connection = mdb.connect(host=self.host, user=self.username, port=self.port, passwd=self.password)
60+
return self.connection
61+
except Exception:
62+
self.reconnect()
6063

6164
def stop(self):
6265
""" Stop running this thread and close connection """

0 commit comments

Comments
 (0)