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

Commit df9676b6 by Sascha Depold

fixed memory leak by correctly unbinding client listeners

1 parent cb5f8b1f
......@@ -21,7 +21,7 @@ ConnectorManager.prototype.connect = function() {
database: this.config.database
})
this.client.setMaxListeners(Math.pow(2,32)-1)
this.client.setMaxListeners(this.maxConcurrentQueries)
}
ConnectorManager.prototype.query = function(sql, callee, options) {
......
var Utils = require("./utils")
var Query = module.exports = function(client, callee, options) {
var self = this
this.client = client
this.callee = callee
this.options = options || {}
this.client.on('error', function(err) { self.onFailure(err) })
this.bindClientFunction = function(err) { self.onFailure(err) }
}
Utils.addEventEmitter(Query)
......@@ -14,6 +11,8 @@ Query.prototype.run = function(query) {
var self = this
this.sql = query
this.bindClient()
if(this.options.logging)
console.log('Executing: ' + this.sql)
......@@ -24,10 +23,18 @@ Query.prototype.run = function(query) {
return this
}
Query.prototype.bindClient = function() {
this.client.on('error', this.bindClientFunction)
}
Query.prototype.unbindClient = function() {
this.client.removeListener('error', this.bindClientFunction)
}
Query.prototype.onSuccess = function(query, results, fields) {
var result = this.callee
, self = this
// add the inserted row id to the instance
if (this.callee && (query.indexOf('INSERT INTO') == 0) && (results.hasOwnProperty('insertId')))
this.callee[this.callee.definition.autoIncrementField] = results.insertId
......@@ -41,9 +48,11 @@ Query.prototype.onSuccess = function(query, results, fields) {
result = (result.length == 0) ? null : result[0]
}
this.unbindClient()
this.emit('success', result)
}
Query.prototype.onFailure = function(err) {
this.unbindClient()
this.emit('failure', err, this.callee)
}
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!