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
Create a separate hook runner for onSend hooks #795
Create a separate hook runner for onSend hooks #795
Conversation
The `onSend` hooks are a special case because they need extra logic for changing the payload. This extra logic is not needed for the other hooks and it makes the other hooks more prone to a bug where the hook runner's internal state will be changed if a hook function returns a promise that resolves to a value that is not `undefined`. This change adds a second hook runner just for `onSend` hooks that helps simplify the logic for calling the runner (it's no longer necessary to call `.bind(reply)` during a request) and the main hook runner is simplified so that changing its internal state is no longer possible. This also improves the hooks benchmarks by 450-600 req/sec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add a test for the original bug you wanted to solve?
I mean one using the external API.
Il giorno dom 18 feb 2018 alle 08:45 Nathan Woltman <
notifications@github.com> ha scritto:
… It's right here:
https://github.com/fastify/fastify/pull/795/files#diff-810aa058de5dd12d6a4d43556a2eb5e6R178
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#795 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AADL498uoKGnfqSCz-C90q4IBgyatO2Jks5tV9UQgaJpZM4SJhi5>
.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
The
onSend
hooks are a special case because they need extra logic for changing the payload. This extra logic is not needed for the other hooks and it makes the other hooks prone to a bug where the hook runner's internal state will be changed if a hook function returns a promise that resolves to a value other thanundefined
.Example of the bug that this change prevents
This change adds a second hook runner just for
onSend
hooks that helps make the code that starts the hooks cleaner (it's no longer necessary to call.bind(reply)
during a request) and the main hook runner is simplified so that changing its internal state is no longer possible.This also improves the hooks benchmark by 450-600 req/sec.
Benchmark
Before
After
Checklist
npm run test
andnpm run benchmark