diff --git a/index.js b/index.js index 8136c389..a6960081 100644 --- a/index.js +++ b/index.js @@ -154,13 +154,15 @@ Cursor.prototype._getRows = function(rows, cb) { this.connection.flush() } -Cursor.prototype.end = function(cb) { +// users really shouldn't be calling 'end' here and terminating a connection to postgres +// via the low level connection.end api +Cursor.prototype.end = util.deprecate(function(cb) { if (this.state !== 'initialized') { this.connection.sync() } this.connection.once('end', cb) this.connection.end() -} +}, 'Cursor.end is deprecated. Call end on the client itself to end a connection to the database.') Cursor.prototype.close = function(cb) { if (this.state === 'done') { diff --git a/test/pool.js b/test/pool.js index bd487807..80e0ddc1 100644 --- a/test/pool.js +++ b/test/pool.js @@ -83,4 +83,24 @@ describe('pool', function() { done() }) }) + + it('can close multiple times on a pool', async function() { + const pool = new pg.Pool({ max: 1 }) + const run = () => + new Promise(async resolve => { + const cursor = new Cursor(text) + const client = await pool.connect() + client.query(cursor) + cursor.read(25, function(err) { + assert.ifError(err) + cursor.close(function(err) { + assert.ifError(err) + client.release() + resolve() + }) + }) + }) + await Promise.all([run(), run(), run()]) + await pool.end() + }) })