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
2 changes: 2 additions & 0 deletions cf/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ function Postgres(a, b) {
])
} catch (error) {
throw error
} finally {
connection && (connection.onclose = null)
}

async function scope(c, fn, name) {
Expand Down
2 changes: 2 additions & 0 deletions cjs/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ function Postgres(a, b) {
])
} catch (error) {
throw error
} finally {
connection && (connection.onclose = null)
}

async function scope(c, fn, name) {
Expand Down
15 changes: 15 additions & 0 deletions cjs/tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2420,6 +2420,21 @@ t('Ensure transactions throw if connection is closed dwhile there is no query',
return ['CONNECTION_CLOSED', x.code]
})

t('Does not reject leftover begin onclose after commit', async() => {
const sql = postgres({ ...options, max: 1 })
const rejections = []
const onUnhandled = reason => rejections.push(reason)
process.on('unhandledRejection', onUnhandled)
try {
await sql.begin(sql => sql`select 1`)
await sql.end({ timeout: 0 })
await delay(50)
} finally {
process.off('unhandledRejection', onUnhandled)
}
return [0, rejections.length]
})

t('Custom socket', {}, async() => {
let result
const sql = postgres({
Expand Down
2 changes: 2 additions & 0 deletions deno/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ function Postgres(a, b) {
])
} catch (error) {
throw error
} finally {
connection && (connection.onclose = null)
}

async function scope(c, fn, name) {
Expand Down
15 changes: 15 additions & 0 deletions deno/tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2422,6 +2422,21 @@ t('Ensure transactions throw if connection is closed dwhile there is no query',
return ['CONNECTION_CLOSED', x.code]
})

t('Does not reject leftover begin onclose after commit', async() => {
const sql = postgres({ ...options, max: 1 })
const rejections = []
const onUnhandled = reason => rejections.push(reason)
process.on('unhandledRejection', onUnhandled)
try {
await sql.begin(sql => sql`select 1`)
await sql.end({ timeout: 0 })
await delay(50)
} finally {
process.off('unhandledRejection', onUnhandled)
}
return [0, rejections.length]
})

t('Custom socket', {}, async() => {
let result
const sql = postgres({
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ function Postgres(a, b) {
])
} catch (error) {
throw error
} finally {
connection && (connection.onclose = null)
}

async function scope(c, fn, name) {
Expand Down
15 changes: 15 additions & 0 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2420,6 +2420,21 @@ t('Ensure transactions throw if connection is closed dwhile there is no query',
return ['CONNECTION_CLOSED', x.code]
})

t('Does not reject leftover begin onclose after commit', async() => {
const sql = postgres({ ...options, max: 1 })
const rejections = []
const onUnhandled = reason => rejections.push(reason)
process.on('unhandledRejection', onUnhandled)
try {
await sql.begin(sql => sql`select 1`)
await sql.end({ timeout: 0 })
await delay(50)
} finally {
process.off('unhandledRejection', onUnhandled)
}
return [0, rejections.length]
})

t('Custom socket', {}, async() => {
let result
const sql = postgres({
Expand Down