Skip to content

Commit

Permalink
Ensure queries are not pushed on connections with active cursors - fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
porsager committed Mar 8, 2023
1 parent f68e345 commit 4f987d5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
build(q)
return write(toBuffer(q))
&& !q.describeFirst
&& !q.cursorFn
&& sent.length < max_pipeline
&& (!q.options.onexecute || q.options.onexecute(connection))
} catch (error) {
Expand Down
21 changes: 21 additions & 0 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2472,3 +2472,24 @@ t('Insert array with undefined transform', async() => {
await sql`drop table test`
]
})

t('concurrent cursors', async() => {
const xs = []

await Promise.all([...Array(7)].map((x, i) => [
sql`select ${ i }::int as a, generate_series(1, 2) as x`.cursor(([x]) => xs.push(x.a + x.x))
]).flat())

return ['12233445566778', xs.join('')]
})

t('concurrent cursors multiple connections', async() => {
const sql = postgres({ ...options, max: 2 })
const xs = []

await Promise.all([...Array(7)].map((x, i) => [
sql`select ${ i }::int as a, generate_series(1, 2) as x`.cursor(([x]) => xs.push(x.a + x.x))
]).flat())

return ['12233445566778', xs.sort().join('')]
})

0 comments on commit 4f987d5

Please sign in to comment.