-
Notifications
You must be signed in to change notification settings - Fork 53
🐛 Automatically expire idle db connections after one minute #877
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
WalkthroughAdds a SQLAlchemy engine connect-event listener to set PostgreSQL session parameters (idle_session_timeout, idle_in_transaction_session_timeout, application_name) on each new connection. No public interfaces changed. Changes
Sequence Diagram(s)sequenceDiagram
actor App
participant Engine as SQLAlchemy Engine
participant PG as PostgreSQL
App->>Engine: Acquire connection
activate Engine
Engine-->>PG: Open connection
activate PG
Note right of Engine: on_connect event fires
Engine->>PG: SET idle_session_timeout = '1min'
Engine->>PG: SET idle_in_transaction_session_timeout = '1min'
Engine->>PG: SET application_name = 'kai-solution-server'
PG-->>Engine: OK
deactivate PG
Engine-->>App: Connection ready
deactivate Engine
alt Error setting parameters
PG-->>Engine: Error
Engine-->>App: Propagate connection error
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Signed-off-by: Fabian von Feilitzsch <[email protected]>
d861799 to
210a15f
Compare
JonahSussman
left a comment
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
|
/cherry-pick release-0.8 |
|
/cherrypick release-0.8 |
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
kai_mcp_solution_server/src/kai_mcp_solution_server/db/dao.py (1)
143-143: Remove unused parameter to clean up the function signature.The
conn_recordparameter is not used in the function. While SQLAlchemy event listeners often have standardized signatures where not all parameters are used, removing unused parameters improves code clarity.- def _set_pg_timeouts(dbapi_conn: Any, conn_record: Any) -> None: + def _set_pg_timeouts(dbapi_conn: Any, _conn_record: Any) -> None:Alternatively, if the parameter is truly unnecessary:
- def _set_pg_timeouts(dbapi_conn: Any, conn_record: Any) -> None: + def _set_pg_timeouts(dbapi_conn: Any, *_: Any) -> None:
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
kai_mcp_solution_server/src/kai_mcp_solution_server/db/dao.py(1 hunks)
🧰 Additional context used
🪛 Ruff (0.13.1)
kai_mcp_solution_server/src/kai_mcp_solution_server/db/dao.py
143-143: Unused function argument: conn_record
(ARG001)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: Run e2e test (windows-latest, cmd, ChatOpenAI, kai-test-generation)
- GitHub Check: Run e2e test (ubuntu-22.04-arm, bash, ChatOpenAI, kai-test-generation)
- GitHub Check: Run e2e test (ubuntu-24.04, bash, ChatOpenAI, kai-test-generation)
- GitHub Check: Run e2e test (macos-latest, bash, ChatOpenAI, kai-test-generation)
- GitHub Check: Run e2e test (macos-13, bash, ChatOpenAI, kai-test-generation)
🔇 Additional comments (2)
kai_mcp_solution_server/src/kai_mcp_solution_server/db/dao.py (2)
142-148: LGTM! Good connection timeout configuration for PostgreSQL.The event listener properly sets PostgreSQL session timeouts to prevent idle connections from consuming resources. The 1-minute timeout aligns with the PR objective and will help maintain database health.
142-148: Verify PostgreSQL-specific settings don't affect other database types.The event listener is registered for all non-SQLite databases, but the SQL commands (
SET idle_session_timeout, etc.) are PostgreSQL-specific. This could cause errors with MySQL, MariaDB, or other database types.Run this script to check if the codebase supports multiple database types:
Signed-off-by: Fabian von Feilitzsch <[email protected]>
Signed-off-by: Fabian von Feilitzsch <[email protected]>
Summary by CodeRabbit