-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Closed
Labels
Description
Hey,
I implemented some error handling in case the mysql connection breaks.
function handleDisconnect() {
// Recreate the connection, since
// the old one cannot be reused.
connection = mysql.createConnection(dbConfig);
connection.connect(function(err) {
// The server is either down
// or restarting
if(err) {
// We introduce a delay before attempting to reconnect,
// to avoid a hot loop, and to allow our node script to
// process asynchronous requests in the meantime.
console.log('error when connecting to db:', err);
setTimeout(handleDisconnect, 2000);
}
});
connection.on('error', function(err) {
console.log('db error', err);
if(err.code === 'PROTOCOL_CONNECTION_LOST') {
handleDisconnect();
}else{
throw err;
}
});
}
However after a disconnect I always get a "PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR", even though a new connection should have been established.
When I kill the MySQL Server I get the expected output, I then get an on Connection Error output every two seconds until I restart the MySQL Server. So it's safe to assume that there is a new connection.
However I get the "PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR" when I try to query afterwards. Both If I have or have not queried while the Server was down.
Am I missing something or is this unexpected behavior?