diff --git a/lib/connection/pool.js b/lib/connection/pool.js index 683edb866..a2e6dc2ca 100644 --- a/lib/connection/pool.js +++ b/lib/connection/pool.js @@ -1051,6 +1051,15 @@ function removeConnection(self, connection) { var handlers = ["close", "message", "error", "timeout", "parseError", "connect"]; function _createConnection(self) { + if (self.options.domainsEnabled === true && process.domain) { + // it is not valid to create a connection on a domain since the queries themselves are bound via the domain + // so if we get here on a domain, we exit so the connection and all it's future queries aren't forever coupled to that domain + process.domain.exit(); + return process.nextTick(function() { + return _createConnection(self); + }); + } + if(self.state == DESTROYED || self.state == DESTROYING) { return; }