Description
I am attempting to use PoolCluster for fault tolerance with an ORDER selector where if HOST1 is inaccessible it will be removed from the cluster and HOST2 will be used.
This works well when I run multiple getConnection/query in sync. On first query, if HOST1 is down it is removed and HOST2 is used for all subsequent queries.
However, when I attempt executing queries in async when HOST1 is unavailable:
var mysql = require('mysql');
var poolCluster = mysql.createPoolCluster();
poolCluster.add('h1', host1config);
poolCluster.add('h2', host2config);
poolCluster.getConnection('h*', 'ORDER', function (err, connection) {
if (err) {
console.log(err);
} else {
connection.query('SELECT id FROM mytable LIMIT 1;', function(err, rows) {
if (err) {
console.log(err);
} else {
console.log(rows);
}
});
}
});
poolCluster.getConnection('h*', 'ORDER', function (err, connection) {
if (err) {
console.log(err);
} else {
connection.query('SELECT name FROM mytable LIMIT 1;', function(err, rows) {
if (err) {
console.log(err);
} else {
console.log(rows);
}
});
}
});
I get an exception similar to the following back right away:
Error: connect ECONNREFUSED
at errnoException (net.js:904:11)
at Object.afterConnect [as oncomplete] (net.js:895:19)
The docs mention that I can do something like this to catch fatal exceptions:
connection.on('error', function(err) {
console.log(err.code); // 'ER_BAD_DB_ERROR'
});
but that does not seem to be possible when PoolCluster is involved since the exception seems to be thrown somewhere from getConnection. :(
Is there a way of suppressing these exceptions other than defining an unhandled exception handler in the client?
I am running node 0.10.29 and mysql 2.5.0.
Thank you and I apologize if I am missing something obvious.