Skip to content

Commit da9ace5

Browse files
authored
fix: avoid invoking onError hook when aborted handler resolves (#4631)
Fixes #4626. When a client aborts the request while the route handler is still processing, this no longer triggers an error when the route handler finishes processing.
1 parent ca9785a commit da9ace5

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

lib/route.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,6 @@ function handleOnRequestAbortHooksErrors (reply, err) {
513513
if (err) {
514514
reply.log.error({ err }, 'onRequestAborted hook failed')
515515
}
516-
reply[kReplyIsError] = true
517516
}
518517

519518
function handleTimeout () {

test/hooks.test.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3413,7 +3413,7 @@ test('onRequestAbort should be triggered', t => {
34133413
const fastify = Fastify()
34143414
let order = 0
34153415

3416-
t.plan(9)
3416+
t.plan(7)
34173417
t.teardown(() => fastify.close())
34183418

34193419
fastify.addHook('onRequestAbort', function (req, done) {
@@ -3424,8 +3424,7 @@ test('onRequestAbort should be triggered', t => {
34243424
})
34253425

34263426
fastify.addHook('onError', function hook (request, reply, error, done) {
3427-
t.same(error, { hello: 'world' }, 'onError should be called')
3428-
t.ok(request.raw.aborted, 'request should be aborted')
3427+
t.fail('onError should not be called')
34293428
done()
34303429
})
34313430

0 commit comments

Comments
 (0)