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

Commit aedc12f7 by Mick Hansen

Merge pull request #1137 from peaches/master

Closing postgres client properly
2 parents 359b7cdb 95fbc6fa
Showing with 11 additions and 5 deletions
......@@ -27,6 +27,7 @@ module.exports = (function() {
this.disconnectTimeoutId = null
this.pendingQueries = 0
this.clientDrained = true
this.maxConcurrentQueries = (this.config.maxConcurrentQueries || 50)
process.on('exit', function() {
......@@ -51,6 +52,7 @@ module.exports = (function() {
var self = this
self.pendingQueries++
self.clientDrained = false
return new Utils.CustomEventEmitter(function(emitter) {
self.connect()
......@@ -64,8 +66,6 @@ module.exports = (function() {
.complete(function(err) {
self.endQuery.call(self)
done && done(err) })
.success(function(results) { self.endQuery.call(self) })
.error(function(err) { self.endQuery.call(self) })
.proxy(emitter)
})
}).run()
......@@ -152,6 +152,12 @@ module.exports = (function() {
this.client.connect(function(err, client, done) {
connectCallback(err, client || self.client, done)
})
// Closes a client correctly even if we have backed up queries
// https://github.com/brianc/node-postgres/pull/346
this.client.on('drain', function() {
self.clientDrained = true
})
}
}
......@@ -168,9 +174,9 @@ module.exports = (function() {
}
if (this.client) {
// Closes a client correctly even if we have backed up queries
// https://github.com/brianc/node-postgres/pull/346
this.client.on('drain', this.client.end.bind(this.client))
if (this.clientDrained) {
this.client.end()
}
this.client = null
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!