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
6 changes: 6 additions & 0 deletions packages/pg/lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,12 @@ class Client extends EventEmitter {
if (activeQuery.name) {
delete this.connection.submittedNamedStatements[activeQuery.name]
}
// A paged query drives the portal with flush instead of sync, so on error
// the backend is still ignoring everything until a sync arrives. Send it
// here or ReadyForQuery never comes and the connection stays wedged.
if (activeQuery.rows) {
this.connection.sync()
}
activeQuery.handleError(msg, this.connection)
}

Expand Down
27 changes: 27 additions & 0 deletions packages/pg/test/integration/gh-issues/3707-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const helper = require('../test-helper')
const assert = require('assert')

const suite = new helper.Suite()

// the rows option drives the portal with flush instead of sync, which the native client does not do
if (helper.args.native) {
return
}

suite.test('an error during a rows-limited query does not wedge the connection', async () => {
const client = new helper.pg.Client()
await client.connect()

await assert.rejects(
client.query({
text: 'select 10 / (5 - i) as v from generate_series(1, 7) g(i)',
rows: 2,
}),
/division by zero/
)

const { rows } = await client.query('select 1 as v')
assert.equal(rows[0].v, 1)

await client.end()
})
Loading