mirror of
https://github.com/brianc/node-postgres.git
synced 2026-01-18 15:55:05 +00:00
parent
29877530c6
commit
7c7a3b884d
@ -545,6 +545,15 @@ Client.prototype.query = function (config, values, callback) {
|
||||
Client.prototype.end = function (cb) {
|
||||
this._ending = true
|
||||
|
||||
// if we have never connected, then end is a noop, callback immediately
|
||||
if (this.connection.stream.pending && !this.connection.stream.connecting) {
|
||||
if (cb) {
|
||||
cb()
|
||||
} else {
|
||||
return Promise.resolve()
|
||||
}
|
||||
}
|
||||
|
||||
if (this.activeQuery || !this._queryable) {
|
||||
// if we have an active query we need to force a disconnect
|
||||
// on the socket - otherwise a hung query could block end forever
|
||||
@ -554,10 +563,10 @@ Client.prototype.end = function (cb) {
|
||||
}
|
||||
|
||||
if (cb) {
|
||||
this.connection.once('end', cb)
|
||||
this.connection.stream.once('close', cb)
|
||||
} else {
|
||||
return new this._Promise((resolve) => {
|
||||
this.connection.once('end', resolve)
|
||||
this.connection.stream.once('close', resolve)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
13
packages/pg/test/integration/gh-issues/2108-tests.js
Normal file
13
packages/pg/test/integration/gh-issues/2108-tests.js
Normal file
@ -0,0 +1,13 @@
|
||||
"use strict"
|
||||
var helper = require('./../test-helper')
|
||||
const suite = new helper.Suite()
|
||||
|
||||
suite.test('Closing an unconnected client calls callback', (done) => {
|
||||
const client = new helper.pg.Client()
|
||||
client.end(done)
|
||||
})
|
||||
|
||||
suite.testAsync('Closing an unconnected client resolves promise', () => {
|
||||
const client = new helper.pg.Client()
|
||||
return client.end()
|
||||
})
|
||||
Loading…
x
Reference in New Issue
Block a user