-
-
Notifications
You must be signed in to change notification settings - Fork 9
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: Proxy should always return factory wrapped version of app #46
Conversation
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.
Thanks for opening a PR! Can you please add a unit test?
@@ -743,3 +744,19 @@ test('should restart an app before listening', async (t) => { | |||
await app.close() | |||
t.ok(!app.server.listening) | |||
}) | |||
|
|||
test('should always proxy to the factory wrapped version of app', async (t) => { | |||
async function userProvidedFactory () { |
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.
async function userProvidedFactory () { | |
async function userProvidedFactory (fastify) { |
You should pass a fastify factory param instance here.
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.
Hmm, if you pass the fastify factory as a param (see previous message), your test works on the current version. Not sure that I understand your point. Can you point me to where do you think you receive an app object instead of a proxy wrapper?
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.
@ivan-tymoshenko Hi Ivan, actually, you're correct, while the proxy is set to const app = fastify({ ...newOpts, serverFactory })
in one place, and newApp = await factory(createApplication, opts, restartOptions)
in another, because the proxy contains a reference to the latest copy of the object and the object is being mutated, they are the same.
Our codebase was missing the fastify factory as a param.
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.
See comments above.
Before this change, when the server was first booted, the proxy, which is returned from
restartable
was pointing to a copy of app that's returned fromfastify({ ...newOpts, serverFactory })
, but fromawait factory(createApplication, opts, restartOptions)
(with the user provided factory wrapper) after restarts.On first boot
app
is a reference to what was returned from thefastify
wrapper:restartable/index.js
Line 92 in 0b02b0d
restartable/index.js
Line 95 in 0b02b0d
On reboot
newApp
is a reference to the output of the usersfactory
wrapper:restartable/index.js
Line 27 in 0b02b0d
restartable/index.js
Line 50 in 0b02b0d
It was not possible to access the copy of app wrapped by
factory
, unless the server was restarted immediately after fist boot.With this proposed change, the proxy always points to the latest copy of the app wrapped by the users factory.
Fixes #45
Checklist
npm run test
andnpm run benchmark
and the Code of conduct