Skip to content

Commit 3f9118b

Browse files
committed
Ensure drain only dequeues if ready - fixes porsager#303
1 parent 62786b0 commit 3f9118b

File tree

6 files changed

+36
-3
lines changed

6 files changed

+36
-3
lines changed

cjs/src/connection.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
299299

300300
/* c8 ignore next 3 */
301301
function drain() {
302-
onopen(connection)
302+
!query && onopen(connection)
303303
}
304304

305305
function data(x) {

cjs/tests/index.js

+11
Original file line numberDiff line numberDiff line change
@@ -1977,3 +1977,14 @@ t('Custom socket works', {}, async() => {
19771977
82
19781978
]
19791979
})
1980+
1981+
t('Ensure drain only dequeues if ready', async() => {
1982+
const sql = postgres(options)
1983+
1984+
const res = await Promise.all([
1985+
sql.unsafe('SELECT 0+$1 --' + '.'.repeat(100000), [1]),
1986+
sql.unsafe('SELECT 0+$1+$2+$3', [1, 2, 3])
1987+
])
1988+
1989+
return [res.length, 2]
1990+
})

deno/src/connection.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
302302

303303
/* c8 ignore next 3 */
304304
function drain() {
305-
onopen(connection)
305+
!query && onopen(connection)
306306
}
307307

308308
function data(x) {

deno/tests/index.js

+11
Original file line numberDiff line numberDiff line change
@@ -1980,4 +1980,15 @@ t('Custom socket works', {}, async() => {
19801980
]
19811981
})
19821982

1983+
t('Ensure drain only dequeues if ready', async() => {
1984+
const sql = postgres(options)
1985+
1986+
const res = await Promise.all([
1987+
sql.unsafe('SELECT 0+$1 --' + '.'.repeat(100000), [1]),
1988+
sql.unsafe('SELECT 0+$1+$2+$3', [1, 2, 3])
1989+
])
1990+
1991+
return [res.length, 2]
1992+
})
1993+
19831994
;window.addEventListener("unload", () => Deno.exit(process.exitCode))

src/connection.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
299299

300300
/* c8 ignore next 3 */
301301
function drain() {
302-
onopen(connection)
302+
!query && onopen(connection)
303303
}
304304

305305
function data(x) {

tests/index.js

+11
Original file line numberDiff line numberDiff line change
@@ -1977,3 +1977,14 @@ t('Custom socket works', {}, async() => {
19771977
82
19781978
]
19791979
})
1980+
1981+
t('Ensure drain only dequeues if ready', async() => {
1982+
const sql = postgres(options)
1983+
1984+
const res = await Promise.all([
1985+
sql.unsafe('SELECT 0+$1 --' + '.'.repeat(100000), [1]),
1986+
sql.unsafe('SELECT 0+$1+$2+$3', [1, 2, 3])
1987+
])
1988+
1989+
return [res.length, 2]
1990+
})

0 commit comments

Comments
 (0)