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

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