Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 10 additions & 0 deletions packages/pg/lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,21 @@ class Client extends EventEmitter {
}

_handleRowDescription(msg) {
if (this.activeQuery == null) {
const error = new Error('Received unexpected rowDescription message from backend.')
this._handleErrorEvent(error)
return
}
// delegate rowDescription to active query
this.activeQuery.handleRowDescription(msg)
}

_handleDataRow(msg) {
if (this.activeQuery == null) {
const error = new Error('Received unexpected dataRow message from backend.')
this._handleErrorEvent(error)
return
}
// delegate dataRow to active query
this.activeQuery.handleDataRow(msg)
}
Expand Down
15 changes: 15 additions & 0 deletions packages/pg/test/integration/gh-issues/3174-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const buffers = require('../../test-buffers')
const helper = require('../test-helper')
const assert = require('assert')
const cli = require('../../cli')
const Cursor = require('../../../../pg-cursor')

const suite = new helper.Suite()

Expand Down Expand Up @@ -106,6 +107,18 @@ const testErrorBuffer = (bufferName, errorBuffer) => {
await assert.rejects(() => client.query('SELECTR NOW()'), 'Further queries on the client should reject')
}

// Same run but using cursor
const cursor = await client.query(new Cursor('SELECT NOW()'))
cursor.read(100, () => {})
await cursor.close()
await delay(50)

if (!cli.native) {
assert(errorHit)
// further queries on the client should fail since its in an invalid state
await assert.rejects(() => client.query('SELECTR NOW()'), 'Further queries on the client should reject')
}

await closeServer()
})

Expand Down Expand Up @@ -164,4 +177,6 @@ const testErrorBuffer = (bufferName, errorBuffer) => {
if (!helper.args.native) {
testErrorBuffer('parseComplete', buffers.parseComplete())
testErrorBuffer('commandComplete', buffers.commandComplete('f'))
testErrorBuffer('rowDescription', buffers.rowDescription())
testErrorBuffer('dataRow', buffers.dataRow())
}