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

Commit 07c67c43 by Mick Hansen

Fix transaction memory leak issue

1 parent 048516f8
......@@ -24,5 +24,11 @@ module.exports = (function(){
this.connect()
}
ConnectorManager.prototype.cleanup = function() {
if (this.onProcessExit) {
process.removeListener('exit', this.onProcessExit)
}
}
return ConnectorManager
})()
......@@ -142,7 +142,7 @@ module.exports = (function() {
})
}
process.on('exit', function () {
this.onProcessExit = function () {
//be nice & close our connections on exit
if (self.pool) {
self.pool.drain()
......@@ -151,7 +151,9 @@ module.exports = (function() {
}
return
})
}.bind(this);
process.on('exit', this.onProcessExit)
}
Utils._.extend(ConnectorManager.prototype, require("../connector-manager").prototype)
......
......@@ -143,7 +143,7 @@ module.exports = (function() {
})
}
process.on('exit', function () {
this.onProcessExit = function () {
//be nice & close our connections on exit
if (self.pool) {
self.pool.drain()
......@@ -152,7 +152,9 @@ module.exports = (function() {
}
return
})
}.bind(this);
process.on('exit', this.onProcessExit)
}
Utils._.extend(ConnectorManager.prototype, require("../connector-manager").prototype);
......
......@@ -30,9 +30,11 @@ module.exports = (function() {
this.clientDrained = true
this.maxConcurrentQueries = (this.config.maxConcurrentQueries || 50)
process.on('exit', function() {
this.onProcessExit = function () {
this.disconnect()
}.bind(this))
}.bind(this);
process.on('exit', this.onProcessExit)
}
Utils._.extend(ConnectorManager.prototype, require("../connector-manager").prototype)
......
......@@ -35,6 +35,11 @@ TransactionManager.prototype.getConnectorManager = function(uuid) {
return this.connectorManagers[uuid]
}
TransactionManager.prototype.releaseConnectionManager = function(uuid) {
this.connectorManagers[uuid].cleanup();
delete this.connectorManagers[uuid]
}
TransactionManager.prototype.query = function(sql, callee, options) {
options = options || {}
options.uuid = 'default'
......
......@@ -25,6 +25,7 @@ Transaction.prototype.commit = function() {
.getQueryInterface()
.commitTransaction(this, {})
.proxy(this)
.done(this.cleanup.bind(this))
}
......@@ -34,6 +35,7 @@ Transaction.prototype.rollback = function() {
.getQueryInterface()
.rollbackTransaction(this, {})
.proxy(this)
.done(this.cleanup.bind(this))
}
Transaction.prototype.prepareEnvironment = function(callback) {
......@@ -76,6 +78,10 @@ Transaction.prototype.setIsolationLevel = function(callback) {
.error(onError.bind(this))
}
Transaction.prototype.cleanup = function() {
this.sequelize.transactionManager.releaseConnectionManager(this.id)
}
// private
var onError = function(err) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!