Skip to content

Commit 3851547

Browse files
committed
fixup
1 parent 939cf3f commit 3851547

4 files changed

Lines changed: 343 additions & 343 deletions

File tree

lib/api/api-request.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const assert = require('node:assert')
44
const { Readable } = require('./readable')
5-
const { InvalidArgumentError, AbortError } = require('../core/errors')
5+
const { InvalidArgumentError, RequestAbortedError } = require('../core/errors')
66
const util = require('../core/util')
77
const { getResolveErrorBodyCallback } = require('./util')
88
const { AsyncResource } = require('node:async_hooks')
@@ -66,10 +66,10 @@ class RequestHandler extends AsyncResource {
6666

6767
if (this.signal) {
6868
if (this.signal.aborted) {
69-
this.reason = this.signal.reason ?? new AbortError()
69+
this.reason = this.signal.reason ?? new RequestAbortedError()
7070
} else {
7171
this.removeAbortListener = util.addAbortListener(this.signal, () => {
72-
this.reason = this.signal.reason ?? new AbortError()
72+
this.reason = this.signal.reason ?? new RequestAbortedError()
7373
if (this.res) {
7474
util.destroy(this.res, this.reason)
7575
} else if (this.abort) {
@@ -152,6 +152,8 @@ class RequestHandler extends AsyncResource {
152152
onError (err) {
153153
const { res, callback, body, opaque } = this
154154

155+
this.removeAbortListener?.()
156+
155157
if (callback) {
156158
// TODO: Does this need queueMicrotask?
157159
this.callback = null
@@ -166,8 +168,6 @@ class RequestHandler extends AsyncResource {
166168
queueMicrotask(() => {
167169
util.destroy(res, err)
168170
})
169-
} else if (this.removeAbortListener) {
170-
this.removeAbortListener()
171171
}
172172

173173
if (body) {

test/client-request.js

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -135,45 +135,45 @@ test('request hwm', async (t) => {
135135
await t.completed
136136
})
137137

138-
// test('request abort before headers', async (t) => {
139-
// t = tspl(t, { plan: 6 })
140-
141-
// const signal = new EE()
142-
// const server = createServer((req, res) => {
143-
// res.end('hello')
144-
// signal.emit('abort')
145-
// })
146-
// after(() => server.close())
147-
148-
// server.listen(0, () => {
149-
// const client = new Client(`http://localhost:${server.address().port}`)
150-
// after(() => client.destroy())
151-
152-
// client[kConnect](() => {
153-
// client.request({
154-
// path: '/',
155-
// method: 'GET',
156-
// signal
157-
// }, (err) => {
158-
// t.ok(err instanceof errors.RequestAbortedError)
159-
// t.strictEqual(signal.listenerCount('abort'), 0)
160-
// })
161-
// t.strictEqual(signal.listenerCount('abort'), 1)
162-
163-
// client.request({
164-
// path: '/',
165-
// method: 'GET',
166-
// signal
167-
// }, (err) => {
168-
// t.ok(err instanceof errors.RequestAbortedError)
169-
// t.strictEqual(signal.listenerCount('abort'), 0)
170-
// })
171-
// t.strictEqual(signal.listenerCount('abort'), 2)
172-
// })
173-
// })
174-
175-
// await t.completed
176-
// })
138+
test('request abort before headers', async (t) => {
139+
t = tspl(t, { plan: 6 })
140+
141+
const signal = new EE()
142+
const server = createServer((req, res) => {
143+
res.end('hello')
144+
signal.emit('abort')
145+
})
146+
after(() => server.close())
147+
148+
server.listen(0, () => {
149+
const client = new Client(`http://localhost:${server.address().port}`)
150+
after(() => client.destroy())
151+
152+
client[kConnect](() => {
153+
client.request({
154+
path: '/',
155+
method: 'GET',
156+
signal
157+
}, (err) => {
158+
t.ok(err instanceof errors.RequestAbortedError)
159+
t.strictEqual(signal.listenerCount('abort'), 1)
160+
})
161+
t.strictEqual(signal.listenerCount('abort'), 1)
162+
163+
client.request({
164+
path: '/',
165+
method: 'GET',
166+
signal
167+
}, (err) => {
168+
t.ok(err instanceof errors.RequestAbortedError)
169+
t.strictEqual(signal.listenerCount('abort'), 0)
170+
})
171+
t.strictEqual(signal.listenerCount('abort'), 2)
172+
})
173+
})
174+
175+
await t.completed
176+
})
177177

178178
test('request body destroyed on invalid callback', async (t) => {
179179
t = tspl(t, { plan: 1 })

0 commit comments

Comments
 (0)