Skip to content

Commit

Permalink
AbortSignal compatibility fixes for older Node.js versions
Browse files Browse the repository at this point in the history
  • Loading branch information
boromisp committed May 12, 2024
1 parent c022bba commit b703771
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/pg/lib/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class Query extends EventEmitter {
}
if (this._cancelSignal) {
if (this._cancelSignal.aborted) {
return this._cancelSignal.reason
return this._cancelSignal.reason || Object.assign(new Error(), { name: 'AbortError' })
}
this._cancellation = setupCancellation(this._cancelSignal, connection)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,11 @@ suite.test('query can be canceled with abort signal', function (done) {

suite.test('long abort signal timeout does not keep the query / connection going', function (done) {
const client = new Client()
const signal = AbortSignal.timeout(10_000)
const ac = new AbortController()
setTimeout(() => ac.abort(), 10000).unref()

client.query(
new pg.Query({ text: 'SELECT pg_sleep(0.1)', signal }),
new pg.Query({ text: 'SELECT pg_sleep(0.1)', signal: ac.signal }),
assert.success((result) => {
assert.equal(result.rows[0].pg_sleep, '')
client.end(done)
Expand Down

0 comments on commit b703771

Please sign in to comment.