Skip to content

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

Conversation

guillaumejacquart
Copy link
Contributor

@guillaumejacquart guillaumejacquart commented May 27, 2025

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

  • PR title and summary are descriptive. (conventions)
  • Docs updated or follow-up ticket created.
  • Tests included.
  • PR Labeled with release/backport (if the PR is an urgent fix that needs to be backported)

Copy link

codecov bot commented May 27, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

@n8n-assistant n8n-assistant bot added core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team labels May 27, 2025
@guillaumejacquart guillaumejacquart force-pushed the pay-2846-community-issue-endpoint-healthzreadiness-returning-statusok branch 2 times, most recently from f60889a to 2f1db7a Compare May 28, 2025 07:35
@guillaumejacquart guillaumejacquart marked this pull request as ready for review May 28, 2025 10:02
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a 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)
@guillaumejacquart guillaumejacquart force-pushed the pay-2846-community-issue-endpoint-healthzreadiness-returning-statusok branch from 2f1db7a to 53c8ce3 Compare May 30, 2025 08:53
Copy link
Contributor

@MarcL MarcL left a 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.

@shortstacked
Copy link
Contributor

Workflow Test Results 📊 🔴 1 Failed, ⚠️ 1 Warnings, 👍 81 Successful out of 83 total workflows.

Detail: Workflows failing: 237: Workflow contains 1 deleted data. View full workflow run

Tested Ref: 53c8ce32c6f39578732e5376269a3f08a5965abe by @MarcL

❌ Failed Tests (1)

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.

Copy link
Contributor

✅ All Cypress E2E specs passed

@guillaumejacquart guillaumejacquart requested review from a team, alexgrozav and netroy and removed request for a team May 30, 2025 12:07
@guillaumejacquart
Copy link
Contributor Author

@netroy I added you as reviewer since we discussed it in this closed PR : #15686

Copy link
Member

@netroy netroy left a 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';
Copy link
Member

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,
Copy link
Member

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.

@shortstacked
Copy link
Contributor

Workflow Test Results 📊 🔴 2 Failed, ⚠️ 4 Warnings, 👍 77 Successful out of 83 total workflows.

Detail: Workflows failing: 237: Workflow contains 1 deleted data. View full workflow run

Tested Ref: 53c8ce32c6f39578732e5376269a3f08a5965abe by @netroy

❌ Failed Tests (2)

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.

Copy link
Contributor

github-actions bot commented Jun 3, 2025

✅ All Cypress E2E specs passed

@netroy netroy merged commit ac06610 into master Jun 3, 2025
72 checks passed
@netroy netroy deleted the pay-2846-community-issue-endpoint-healthzreadiness-returning-statusok branch June 3, 2025 10:07
Alexandero89 pushed a commit to Alexandero89/n8n that referenced this pull request Jun 4, 2025
Alexandero89 pushed a commit to Alexandero89/n8n that referenced this pull request Jun 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants