Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(#3736): back-port 183f8e9 to v6.x #3855

Merged
merged 2 commits into from
Nov 21, 2024
Merged
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: 1 addition & 1 deletion lib/api/api-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class RequestHandler extends AsyncResource {
this.removeAbortListener = util.addAbortListener(this.signal, () => {
this.reason = this.signal.reason ?? new RequestAbortedError()
if (this.res) {
util.destroy(this.res, this.reason)
util.destroy(this.res.on('error', util.nop), this.reason)
} else if (this.abort) {
this.abort(this.reason)
}
Expand Down
36 changes: 36 additions & 0 deletions test/client-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -1252,3 +1252,39 @@ test('request post body DataView', async (t) => {

await t.completed
})

test('#3736 - Aborted Response (without consuming body)', async (t) => {
const plan = tspl(t, { plan: 1 })

const controller = new AbortController()
const server = createServer((req, res) => {
setTimeout(() => {
res.writeHead(200, 'ok', {
'content-type': 'text/plain'
})
res.write('hello from server')
res.end()
}, 100)
})

server.listen(0)

await EE.once(server, 'listening')
const client = new Client(`http://localhost:${server.address().port}`)

after(server.close.bind(server))
after(client.destroy.bind(client))

const { signal } = controller
const promise = client.request({
path: '/',
method: 'GET',
signal
})

controller.abort()

await plan.rejects(promise, { message: 'This operation was aborted' })

await plan.completed
})
24 changes: 8 additions & 16 deletions test/http2.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,23 +334,15 @@ test(

after(() => server.close())
after(() => client.close())
t = tspl(t, { plan: 2 })
t = tspl(t, { plan: 1 })

try {
await client.request({
path: '/',
method: 'GET',
headers: {
'x-my-header': 'foo'
}
})
} catch (error) {
t.strictEqual(
error.message,
'Client network socket disconnected before secure TLS connection was established'
)
t.strictEqual(error.code, 'ECONNRESET')
}
await t.rejects(client.request({
path: '/',
method: 'GET',
headers: {
'x-my-header': 'foo'
}
}))
}
)

Expand Down
Loading