mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
Call callback when end called on unconnected client (#2109)
* Call callback when end called on unconnected client Closes #2108 * Revert a bit of the change * Use readyState because pending doesn't exist in node 8.x * Update packages/pg/lib/client.js use bring your own promise Co-Authored-By: Charmander <~@charmander.me> Co-authored-by: Charmander <~@charmander.me>
This commit is contained in:
parent
29877530c6
commit
1c8b6b93cf
@ -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.readyState === 'closed') {
|
||||
if (cb) {
|
||||
cb()
|
||||
} else {
|
||||
return this._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
|
||||
|
||||
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