Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/pg/lib/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,12 @@ class Query extends EventEmitter {
}

handleError(err, connection) {
// need to sync after error during a prepared statement
// rows-mode uses Flush instead of pipelining Sync in _getRows. After an
// ErrorResponse the backend ignores messages until Sync, so send one here
// to ensure ReadyForQuery arrives and the client can process later queries.
if (this.rows) {
connection.sync()
}
if (this._canceledDueToError) {
err = this._canceledDueToError
this._canceledDueToError = false
Expand Down
36 changes: 36 additions & 0 deletions packages/pg/test/unit/client/query-error-sync-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict'
const helper = require('./test-helper')
const Query = require('../../../lib/query')
const assert = require('assert')
const suite = new helper.Suite()
const test = suite.test.bind(suite)

test('rows-mode query syncs after an error', function () {
let syncCalls = 0
const query = new Query({ text: 'select 1', rows: 2 }, function (err) {
assert.equal(err.message, 'boom')
})

query.handleError(new Error('boom'), {
sync: function () {
syncCalls++
},
})

assert.equal(syncCalls, 1)
})

test('normal query does not send an extra sync after an error', function () {
let syncCalls = 0
const query = new Query({ text: 'select 1' }, function (err) {
assert.equal(err.message, 'boom')
})

query.handleError(new Error('boom'), {
sync: function () {
syncCalls++
},
})

assert.equal(syncCalls, 0)
})
Loading