Skip to content

Commit 353ab63

Browse files
authored
fix(#3736): back-port 183f8e9 to v6.x (#3855)
* fix(#3736): back-port 183f8e9 to v6.x * Backport #3769: fix http2 test
1 parent 61ec353 commit 353ab63

File tree

3 files changed

+45
-17
lines changed

3 files changed

+45
-17
lines changed

lib/api/api-request.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class RequestHandler extends AsyncResource {
7373
this.removeAbortListener = util.addAbortListener(this.signal, () => {
7474
this.reason = this.signal.reason ?? new RequestAbortedError()
7575
if (this.res) {
76-
util.destroy(this.res, this.reason)
76+
util.destroy(this.res.on('error', util.nop), this.reason)
7777
} else if (this.abort) {
7878
this.abort(this.reason)
7979
}

test/client-request.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,3 +1252,39 @@ test('request post body DataView', async (t) => {
12521252

12531253
await t.completed
12541254
})
1255+
1256+
test('#3736 - Aborted Response (without consuming body)', async (t) => {
1257+
const plan = tspl(t, { plan: 1 })
1258+
1259+
const controller = new AbortController()
1260+
const server = createServer((req, res) => {
1261+
setTimeout(() => {
1262+
res.writeHead(200, 'ok', {
1263+
'content-type': 'text/plain'
1264+
})
1265+
res.write('hello from server')
1266+
res.end()
1267+
}, 100)
1268+
})
1269+
1270+
server.listen(0)
1271+
1272+
await EE.once(server, 'listening')
1273+
const client = new Client(`http://localhost:${server.address().port}`)
1274+
1275+
after(server.close.bind(server))
1276+
after(client.destroy.bind(client))
1277+
1278+
const { signal } = controller
1279+
const promise = client.request({
1280+
path: '/',
1281+
method: 'GET',
1282+
signal
1283+
})
1284+
1285+
controller.abort()
1286+
1287+
await plan.rejects(promise, { message: 'This operation was aborted' })
1288+
1289+
await plan.completed
1290+
})

test/http2.js

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -334,23 +334,15 @@ test(
334334

335335
after(() => server.close())
336336
after(() => client.close())
337-
t = tspl(t, { plan: 2 })
337+
t = tspl(t, { plan: 1 })
338338

339-
try {
340-
await client.request({
341-
path: '/',
342-
method: 'GET',
343-
headers: {
344-
'x-my-header': 'foo'
345-
}
346-
})
347-
} catch (error) {
348-
t.strictEqual(
349-
error.message,
350-
'Client network socket disconnected before secure TLS connection was established'
351-
)
352-
t.strictEqual(error.code, 'ECONNRESET')
353-
}
339+
await t.rejects(client.request({
340+
path: '/',
341+
method: 'GET',
342+
headers: {
343+
'x-my-header': 'foo'
344+
}
345+
}))
354346
}
355347
)
356348

0 commit comments

Comments
 (0)