From 620ddc0dede4e5ed1d7e9702c86b6273cfe9d3be Mon Sep 17 00:00:00 2001 From: "Brian M. Carlson" Date: Fri, 4 Aug 2017 17:40:52 -0500 Subject: [PATCH] Do not send close after readyForQuery Close is used to release a named portal (which isn't used by pg-cursor) or when you're early-terminating a cursor on the unnamed portal. Sending 'close' on an connection which has already sent 'readyForQuery' results in the connection responding with a _second_ 'readyForQuery' which causes a lot of issues within node-postgres as 'readyForQuery' is the signal to indicate the client has gone back into the idle state. --- index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/index.js b/index.js index 0827043e..84236fc6 100644 --- a/index.js +++ b/index.js @@ -145,6 +145,9 @@ Cursor.prototype.end = function(cb) { } Cursor.prototype.close = function(cb) { + if (this.state == 'done') { + return setImmediate(cb) + } this.connection.close({type: 'P'}) this.connection.sync() this.state = 'done'