feat(core): Add config to override default database ping interval and default idle connection timeout #15764
+59
−3
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.
Summary
When using postgres or mysql/mariadb as database, typeorm uses a connection pool. When the dabatase password for the current user changes (password rotation for instance), the db-connection ping function that checks the liveness of the db will most likely re-use an existing connection from the pool, that is kept and not refresh when user db password changes. Thus the ping will succeeded, and n8n will still be up even though new connection from the pool will fail.
To fix that, I suggest to offer the possibility to change the database ping interval as well as the idle connection timeout for a connection in the pool.
That way, a user could setup the idle connection timeout to be less than the ping connection timeout, so that a new connection is created for each ping, thus re-validating the credentials.
We should see later if we want this behavior (each ping connection to be new) to be by default.
Related Linear tickets, Github issues, and Community forum posts
https://linear.app/n8n/issue/PAY-2846/community-issue-endpoint-healthzreadiness-returning-statusok-even-when
closes #15480
Review / Merge checklist
release/backport
(if the PR is an urgent fix that needs to be backported)