Skip to content

Commit

Permalink
fix: avoid invoking onError hook when aborted handler resolves (#4631)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
meyfa committed Mar 20, 2023
1 parent ca9785a commit da9ace5
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
1 change: 0 additions & 1 deletion lib/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,6 @@ function handleOnRequestAbortHooksErrors (reply, err) {
if (err) {
reply.log.error({ err }, 'onRequestAborted hook failed')
}
reply[kReplyIsError] = true
}

function handleTimeout () {
Expand Down
5 changes: 2 additions & 3 deletions test/hooks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3413,7 +3413,7 @@ test('onRequestAbort should be triggered', t => {
const fastify = Fastify()
let order = 0

t.plan(9)
t.plan(7)
t.teardown(() => fastify.close())

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

fastify.addHook('onError', function hook (request, reply, error, done) {
t.same(error, { hello: 'world' }, 'onError should be called')
t.ok(request.raw.aborted, 'request should be aborted')
t.fail('onError should not be called')
done()
})

Expand Down

0 comments on commit da9ace5

Please sign in to comment.