Opional connection closing on shutdown hook #1889
Open
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.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Currently, the
SequelizeModule
unconditionally closes the database connection during theonApplicationShutdown
lifecycle hook. In applications that run long-running background tasks (e.g., RabbitMQ consumers), this creates a race condition. An active task may attempt a database query after the connection has been closed, leading to aConnectionManager was closed
error and preventing a truly graceful shutdown.Issue Number: N/A
What is the new behavior?
This PR introduces a new boolean option,
autoCloseConnection
, to the module configuration options.true
to ensure full backward compatibility.autoCloseConnection
is set tofalse
, the module will skip closing the connection during the shutdown lifecycle.This gives developers control over the connection's lifecycle, allowing them to implement an orchestrated shutdown. For example, they can wait for all background tasks to complete before manually closing the Sequelize connection in their own
onApplicationShutdown
hook.Does this PR introduce a breaking change?
Other information
This change enables more robust graceful shutdown patterns for applications with background workers. This PR also includes minor code formatting and dependency updates from
npm audit fix
to align with the project's standards.Example Usage: