-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Error handler for aborted request not called reliably #4626
Comments
Personally I don't think that aborted requests should be considered errors, and we shouldn't be invoking errorHandler there, I would suggest to consider this to be a bug. |
Since the request was aborted I don't see a reason to invoke the error handler as, and it is stated in documentation, the socket no longer exists so no data can be sent to the client. So, to summarize, the overall problem here is that we're invoking the errorHandler and we should not, isn't it? |
Yes, that's how I see it as well, and it appears everyone in this thread agrees so far. |
I think we are all in agreement, so this is just a bug. |
@kibertoad #4611 was added to solve a bug you reported on twitter:
https://twitter.com/kibertoad/status/1631687720769658882 So maybe that was not the right fix after all? Wdyt @Eomm ? |
Fixes fastify#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.
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.
Prerequisites
Fastify version
4.14.1
Plugin version
No response
Node.js version
18.15.0
Operating system
Windows
Operating system version (i.e. 20.04, 11.3, 10)
11
Description
In #4611, logic was added to call the error handler when an aborted request is responded to. This broke one of our tests, since in v4.14.0, aborted requests only caused
onRequestAbort
to be called, but not also the error handler, which is behavior that we depended on.After some investigation, I found out that the error handler isn't even called reliably:
onRequestAbort
hook is registered, the error handler is calledonRequestAbort
hook isn't registered, the error handler is never calledAdditionally, the error passed to the error handler is not
instanceof Error
and doesn't have astatusCode
property, unlike indicated by TypeScript types forFastifyError
, which the parameter is. In fact, the error given is the response object returned from the route handler. This poses a problem for us because we're logging errors, but the response objects can contain sensitive data, which we don't want to log.Steps to Reproduce
Code sample for reproduction:
When invoked as stated above, the output is:
With the line commented out:
Expected Behavior
Preferrably, I wouldn't want aborted requests be considered errors, even when a response is sent (i.e. revert #4611). But I do understand the intent of that PR, so if it's not an option, I'd expect the following:
onRequestAbort
hook is registeredFastifyError
to the error handler, with a generic error message, instead of the response bodyThe text was updated successfully, but these errors were encountered: