Skip to content
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

Add support for graceful shutdown in fastify #843

Merged
merged 5 commits into from
Oct 3, 2023

Conversation

srikrsna-buf
Copy link
Member

Closes #802.

Once Fastify.close is called it waits for requests to complete and immediately blocks new ones. We use the preClose hook, which is called right when close is called, to start a shutdown timeout for requests and close them if the time runs out.

The other option is just to document this so that users can set the shutdownSignal as we do in this PR.

setTimeout(() => {
shutdownController.abort(opts.shutdownError);
}, opts.shutdownTimeoutMs);
done();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't done be called after the grace period? So in the setTimeout callback?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either should be fine, Fastify waits for the requests to finish even there are no preClosehooks.

@srikrsna-buf srikrsna-buf marked this pull request as ready for review October 2, 2023 13:04
@srikrsna-buf srikrsna-buf merged commit 425cf4a into main Oct 3, 2023
3 checks passed
@srikrsna-buf srikrsna-buf deleted the sk/fastify-shutdown-hooks branch October 3, 2023 06:00
@srikrsna-buf srikrsna-buf mentioned this pull request Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use Fastify hooks to shut down services gracefully
2 participants