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

Commit 07c67c43 by Mick Hansen

Fix transaction memory leak issue

1 parent 048516f8
...@@ -24,5 +24,11 @@ module.exports = (function(){ ...@@ -24,5 +24,11 @@ module.exports = (function(){
this.connect() this.connect()
} }
ConnectorManager.prototype.cleanup = function() {
if (this.onProcessExit) {
process.removeListener('exit', this.onProcessExit)
}
}
return ConnectorManager return ConnectorManager
})() })()
...@@ -142,7 +142,7 @@ module.exports = (function() { ...@@ -142,7 +142,7 @@ module.exports = (function() {
}) })
} }
process.on('exit', function () { this.onProcessExit = function () {
//be nice & close our connections on exit //be nice & close our connections on exit
if (self.pool) { if (self.pool) {
self.pool.drain() self.pool.drain()
...@@ -151,7 +151,9 @@ module.exports = (function() { ...@@ -151,7 +151,9 @@ module.exports = (function() {
} }
return return
}) }.bind(this);
process.on('exit', this.onProcessExit)
} }
Utils._.extend(ConnectorManager.prototype, require("../connector-manager").prototype) Utils._.extend(ConnectorManager.prototype, require("../connector-manager").prototype)
......
...@@ -143,7 +143,7 @@ module.exports = (function() { ...@@ -143,7 +143,7 @@ module.exports = (function() {
}) })
} }
process.on('exit', function () { this.onProcessExit = function () {
//be nice & close our connections on exit //be nice & close our connections on exit
if (self.pool) { if (self.pool) {
self.pool.drain() self.pool.drain()
...@@ -152,7 +152,9 @@ module.exports = (function() { ...@@ -152,7 +152,9 @@ module.exports = (function() {
} }
return return
}) }.bind(this);
process.on('exit', this.onProcessExit)
} }
Utils._.extend(ConnectorManager.prototype, require("../connector-manager").prototype); Utils._.extend(ConnectorManager.prototype, require("../connector-manager").prototype);
......
...@@ -30,9 +30,11 @@ module.exports = (function() { ...@@ -30,9 +30,11 @@ module.exports = (function() {
this.clientDrained = true this.clientDrained = true
this.maxConcurrentQueries = (this.config.maxConcurrentQueries || 50) this.maxConcurrentQueries = (this.config.maxConcurrentQueries || 50)
process.on('exit', function() { this.onProcessExit = function () {
this.disconnect() this.disconnect()
}.bind(this)) }.bind(this);
process.on('exit', this.onProcessExit)
} }
Utils._.extend(ConnectorManager.prototype, require("../connector-manager").prototype) Utils._.extend(ConnectorManager.prototype, require("../connector-manager").prototype)
......
...@@ -35,6 +35,11 @@ TransactionManager.prototype.getConnectorManager = function(uuid) { ...@@ -35,6 +35,11 @@ TransactionManager.prototype.getConnectorManager = function(uuid) {
return this.connectorManagers[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) { TransactionManager.prototype.query = function(sql, callee, options) {
options = options || {} options = options || {}
options.uuid = 'default' options.uuid = 'default'
......
...@@ -25,6 +25,7 @@ Transaction.prototype.commit = function() { ...@@ -25,6 +25,7 @@ Transaction.prototype.commit = function() {
.getQueryInterface() .getQueryInterface()
.commitTransaction(this, {}) .commitTransaction(this, {})
.proxy(this) .proxy(this)
.done(this.cleanup.bind(this))
} }
...@@ -34,6 +35,7 @@ Transaction.prototype.rollback = function() { ...@@ -34,6 +35,7 @@ Transaction.prototype.rollback = function() {
.getQueryInterface() .getQueryInterface()
.rollbackTransaction(this, {}) .rollbackTransaction(this, {})
.proxy(this) .proxy(this)
.done(this.cleanup.bind(this))
} }
Transaction.prototype.prepareEnvironment = function(callback) { Transaction.prototype.prepareEnvironment = function(callback) {
...@@ -76,8 +78,12 @@ Transaction.prototype.setIsolationLevel = function(callback) { ...@@ -76,8 +78,12 @@ Transaction.prototype.setIsolationLevel = function(callback) {
.error(onError.bind(this)) .error(onError.bind(this))
} }
Transaction.prototype.cleanup = function() {
this.sequelize.transactionManager.releaseConnectionManager(this.id)
}
// private // private
var onError = function(err) { var onError = function(err) {
this.emit('error', err) this.emit('error', err)
} }
\ 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!