Created
March 25, 2013 04:48
-
-
Save nareshv/5234990 to your computer and use it in GitHub Desktop.
mysql connection error handler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/server/db/mysql.coffee b/src/server/db/mysql.coffee | |
index 76658fc..0b60062 100644 | |
--- a/src/server/db/mysql.coffee | |
+++ b/src/server/db/mysql.coffee | |
@@ -43,6 +43,16 @@ module.exports = MysqlDb = (options) -> | |
client = options.client or mysql.createConnection options | |
client.connect() | |
+ # Listen to the library's error event and take appropriate action | |
+ client.on 'error', (err) -> | |
+ console.error 'Application caught error from mysql driver : ' + err.code | |
+ if err.code is 'PROTOCOL_CONNECTION_LOST' | |
+ console.info 'Issuing a re-connect on the mysql connection.' | |
+ client.connect() | |
+ if err.code is 'ECONNREFUSED' | |
+ console.error 'Looks server is down. Not going to re-connect right now' | |
+ | |
+ | |
snapshot_table = options.schema and "#{options.schema}.#{options.snapshot_table}" or options.snapshot_table | |
operations_table = options.schema and "#{options.schema}.#{options.operations_table}" or options.operations_table | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment