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

Commit e1cc9275 by Meg Sharkey

fix for connection leak

1 parent 5b0e7fab
Showing with 8 additions and 1 deletions
......@@ -14,6 +14,8 @@ module.exports = (function() {
}
Utils._.extend(ConnectorManager.prototype, require("../connector-manager").prototype)
var isConnecting = false
ConnectorManager.prototype.query = function(sql, callee, options) {
if(!this.isConnected) this.connect()
......@@ -29,7 +31,10 @@ module.exports = (function() {
ConnectorManager.prototype.connect = function() {
var self = this
// in case database is slow to connect, prevent orphaning the client
if (this.isConnecting) {
return
}
this.client = require("mysql").createClient({
user: this.config.username,
password: this.config.password,
......@@ -39,11 +44,13 @@ module.exports = (function() {
})
this.client.setMaxListeners(this.maxConcurrentQueries)
this.isConnecting = false
}
ConnectorManager.prototype.disconnect = function() {
var self = this
this.client.end(function() {
// needed to prevent mysql connection leak
self.client.destroy()
self.client = null
})
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!