From 3e4eb35653cc058bcaca4bcf1061143e62d661bf Mon Sep 17 00:00:00 2001 From: Monsyne Dragon Date: Thu, 24 Jul 2014 00:47:35 +0000 Subject: [PATCH] Fix db reconnect issue under django 1.6+ Django's orm layer will not auto-reconnect after it looses the connection to the mysql server, until you manually close the database connection in django 1.6 and above. (see: https://code.djangoproject.com/ticket/21597) This is an issue for persistant connections, as MySQL will timeout inactive connections, and any loss of the db connection will cause the stacktach worker to simply repeat the error "MySQL server has gone away" until restarted. This fix will allow the stacktach worker to properly reconnect. Change-Id: I0b0bc75b7e21fd183f3b0e7a55d727ff98d6f02b --- worker/worker.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/worker/worker.py b/worker/worker.py index dd3cf77..931def1 100644 --- a/worker/worker.py +++ b/worker/worker.py @@ -35,6 +35,7 @@ except ImportError: from pympler.process import ProcessMemoryInfo +from django.db import connection as db_connection from stacktach import db from stacktach import message_service from stacktach import stacklog @@ -171,6 +172,8 @@ def continue_running(): def exit_or_sleep(exit=False): if exit: sys.exit(1) + #so django 1.6+ will properly reconnect + db_connection.close() time.sleep(5)