-
Notifications
You must be signed in to change notification settings - Fork 29.8k
feat(core): Add config to override default database ping interval and default idle connection timeout #15764
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
feat(core): Add config to override default database ping interval and default idle connection timeout #15764
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅ 📢 Thoughts on this report? Let us know! |
f60889a
to
2f1db7a
Compare
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.
cubic reviewed 6 files and found no issues. Review PR in cubic.dev.
…e connection timeout of postgres database (to release a connection from the pool)
2f1db7a
to
53c8ce3
Compare
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.
This looks good to me.
Workflow Test Results 📊 🔴 1 Failed,
|
Workflow ID | Workflow Name | Reason |
---|---|---|
237 | BasicLLMChain:AzureChat | Workflow contains 1 deleted data. |
⚠️ Warnings (1)
Workflow ID | Workflow Name | Reason |
---|---|---|
257 | Agent:auto-fix:anthropic | Workflow contains new data that previously did not exist. |
✅ All Cypress E2E specs passed |
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.
LGTM
@@ -1,4 +1,5 @@ | |||
import { inTest } from '@n8n/backend-common'; | |||
import { DatabaseConfig } from '@n8n/config'; |
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.
If we are going to import this directly, might as well move DatabaseConfig
from @n8n/config
into this same folder.
in a separate PR of-course.
this.pingTimer = setTimeout(async () => await this.ping(), 2000); | ||
this.pingTimer = setTimeout( | ||
async () => await this.ping(), | ||
this.databaseConfig.pingIntervalSeconds * Time.seconds.toMilliseconds, |
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.
we could really benefit from a Duration
type to make all the timeouts a tiny bit more type-safe.
Workflow Test Results 📊 🔴 2 Failed,
|
Workflow ID | Workflow Name | Reason |
---|---|---|
237 | BasicLLMChain:AzureChat | Workflow contains 1 deleted data. |
84 | Matrix:Room:create invite kick leave:RoomMember:ge... | Too Many Requests on node Matrix2 |
⚠️ Warnings (4)
Workflow ID | Workflow Name | Reason |
---|---|---|
35 | Slack:User:getPresence info:UserProfile:get update... | Workflow contains new data that previously did not exist. |
48 | Asana:Project:getAll get:Task:create update move g... | Workflow contains new data that previously did not exist. |
53 | ConvertKit:CustomField:create getAll update delete... | Workflow contains new data that previously did not exist. |
257 | Agent:auto-fix:anthropic | Workflow contains new data that previously did not exist. |
✅ All Cypress E2E specs passed |
… default idle connection timeout (n8n-io#15764)
… default idle connection timeout (n8n-io#15764)
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
#15480
Review / Merge checklist
release/backport
(if the PR is an urgent fix that needs to be backported)