Repository navigation
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A database connection can complete after Fastify's startup timeout and remain usable after
fastify.close(), because cleanup is registered only after initialization succeeds. Late completion can also raise an unhandled error while adding the shutdown hook. Separately, the promise-connection startup query is not returned into its promise chain: a query rejection becomes unhandled and Fastify reports a timeout instead of the SQL error.Install cleanup before initialization, close each client at most once, and await late promise connections during shutdown. Run initialization as a separate plugin step so
after()observes its timeout without stalling awaited registration. Await the startup query in both connector APIs and preserve its original error while cleaning up. mysql2's format helper, runtime guards, and result shapes remain intact.This adapts the lifecycle fix from my MariaDB fork, melroy89/fastify-mariadb#4, where I fixed both registration and startup-cleanup issues. The registration follow-up to #201 is submitted separately; this PR contains only lifecycle changes.
Validation with mysql2 3.24.4, Node.js 24, and isolated MySQL 9.7.2:
npm run lintand all 15 TypeScript assertions passed.Pending promise connections must settle before they can be closed, so shutdown may wait for the configured connectTimeout. Local validation is complete.