Skip to content

Commit 4f987d5

Browse files
committed
Ensure queries are not pushed on connections with active cursors - fixes #411
1 parent f68e345 commit 4f987d5

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/connection.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
166166
build(q)
167167
return write(toBuffer(q))
168168
&& !q.describeFirst
169+
&& !q.cursorFn
169170
&& sent.length < max_pipeline
170171
&& (!q.options.onexecute || q.options.onexecute(connection))
171172
} catch (error) {

tests/index.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2472,3 +2472,24 @@ t('Insert array with undefined transform', async() => {
24722472
await sql`drop table test`
24732473
]
24742474
})
2475+
2476+
t('concurrent cursors', async() => {
2477+
const xs = []
2478+
2479+
await Promise.all([...Array(7)].map((x, i) => [
2480+
sql`select ${ i }::int as a, generate_series(1, 2) as x`.cursor(([x]) => xs.push(x.a + x.x))
2481+
]).flat())
2482+
2483+
return ['12233445566778', xs.join('')]
2484+
})
2485+
2486+
t('concurrent cursors multiple connections', async() => {
2487+
const sql = postgres({ ...options, max: 2 })
2488+
const xs = []
2489+
2490+
await Promise.all([...Array(7)].map((x, i) => [
2491+
sql`select ${ i }::int as a, generate_series(1, 2) as x`.cursor(([x]) => xs.push(x.a + x.x))
2492+
]).flat())
2493+
2494+
return ['12233445566778', xs.sort().join('')]
2495+
})

0 commit comments

Comments
 (0)