不要怂,就是干,撸起袖子干!

Commit 421dd28a by Matt Broadstone

fix tedious error handling

The previous commit incorrectly invalidated the connection, when we
should really be removing the connection from the pool completely.
This also fixes an error in the disconnect logic, which was erroneously
checking connection.connected to identify an already disconnected
connection.
1 parent fcceefdf
Showing with 12 additions and 6 deletions
...@@ -47,11 +47,6 @@ ConnectionManager.prototype.connect = function(config) { ...@@ -47,11 +47,6 @@ ConnectionManager.prototype.connect = function(config) {
var connection = new self.lib.Connection(connectionConfig); var connection = new self.lib.Connection(connectionConfig);
connection.lib = self.lib; connection.lib = self.lib;
// don't let tedious errors take down the entire application
connection.on('error', function(err) {
connection._invalid = true;
});
connection.on('connect', function(err) { connection.on('connect', function(err) {
if (!err) { if (!err) {
resolve(connection); resolve(connection);
...@@ -93,12 +88,23 @@ ConnectionManager.prototype.connect = function(config) { ...@@ -93,12 +88,23 @@ ConnectionManager.prototype.connect = function(config) {
break; break;
} }
}); });
if (config.pool.handleDisconnects) {
connection.on('error', function (err) {
switch (err.code) {
case 'ESOCKET':
case 'ECONNRESET':
self.pool.destroy(connection);
}
});
}
}); });
}; };
ConnectionManager.prototype.disconnect = function(connection) { ConnectionManager.prototype.disconnect = function(connection) {
// Dont disconnect a connection that is already disconnected // Dont disconnect a connection that is already disconnected
if (!connection.connected) { if (!!connection.closed) {
return Promise.resolve(); return Promise.resolve();
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!