Skip to content

Conversation

@gyoge0
Copy link
Collaborator

@gyoge0 gyoge0 commented Nov 6, 2025

GitHub Issues addressed

  • This PR closes

What I did

  • Prompted AI for connection settings we need and added those

Screenshots

  • Before
  • After

Testing

  • A brief explanation of tests done/written or how reviewers can test your work

Questions/Discussions/Notes

Summary by CodeRabbit

  • Chores
    • Improved database connection pooling to reuse connections between requests and reduce overhead.
    • Enabled connection health checks to maintain valid connections.
    • Added connection and query timeouts to limit connection establishment and statement execution durations, improving reliability and resource management.

@coderabbitai
Copy link

coderabbitai bot commented Nov 6, 2025

Walkthrough

Adds PostgreSQL connection reuse and health-check parameters plus connection and statement timeout options to the AWS RDS database settings in configuration.

Changes

Cohort / File(s) Change Summary
Database connection settings
tcf_core/settings/base.py
Added CONN_MAX_AGE = 60, CONN_HEALTH_CHECKS = True, and an OPTIONS dict with connect_timeout: 10 and options: "-c statement_timeout=30000" to the AWS RDS PostgreSQL configuration.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Single-file, configuration-only change.
  • Review focus:
    • Confirm timeout values (connect_timeout, statement_timeout) suit expected request/query patterns.
    • Verify CONN_MAX_AGE and CONN_HEALTH_CHECKS are compatible with deployment and connection pool semantics.

Poem

🐰
A burrow of sockets, reused and kept tight,
Health checks that hop in the soft evening light,
Ten seconds to greet, thirty to say "done",
Connections snug, now the queries can run.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description follows the template structure but is largely incomplete with placeholder content. Critical sections lack actual details: GitHub issue reference is empty, Testing section is unfilled, and Screenshots contain no images. Complete the description by specifying the GitHub issue (if applicable), filling out the Testing section with actual test details or how to verify the changes, and providing specific GitHub Issues addressed or removing that section if none apply.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'configure django's database connections' is concise and directly describes the main change—adding database connection configuration parameters (CONN_MAX_AGE, CONN_HEALTH_CHECKS, OPTIONS, etc.) to Django settings.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch db-connection-timeout

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ed6e9e8 and b3d9902.

📒 Files selected for processing (1)
  • tcf_core/settings/base.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tcf_core/settings/base.py

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Jay-Lalwani
Jay-Lalwani previously approved these changes Nov 6, 2025
@gyoge0 gyoge0 force-pushed the db-connection-timeout branch from d2c71eb to ed6e9e8 Compare November 6, 2025 02:26
@gyoge0 gyoge0 marked this pull request as ready for review November 6, 2025 02:35
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 42fdd7e and ed6e9e8.

📒 Files selected for processing (1)
  • tcf_core/settings/base.py (1 hunks)
🔇 Additional comments (2)
tcf_core/settings/base.py (2)

114-114: Validate the 30-second query timeout against actual workload.

The PR description mentions these settings were "Prompted AI for connection settings needed" without specifics on load testing or query profiling. A 30-second query timeout may be too generous for typical web requests (causing slow user experience) or too restrictive for legitimate batch operations.

Monitor query execution times in production and verify:

  1. What percentage of queries currently exceed 30 seconds?
  2. Are there legitimate long-running queries that need higher limits?
  3. What's the 95th/99th percentile query duration?

Consider making timeout values configurable via environment variables:

            "OPTIONS": {
-               "connect_timeout": 10,  # Timeout for establishing connection
-               "options": "-c statement_timeout=30000",  # 30 second query timeout
+               "connect_timeout": env.int("DB_CONNECT_TIMEOUT", default=10),
+               "options": f"-c statement_timeout={env.int('DB_STATEMENT_TIMEOUT_MS', default=30000)}",
            },

This allows tuning without code changes and different values per environment.


108-108: No action needed — CONN_MAX_AGE setting is appropriate for your deployment.

Your codebase uses Gunicorn with persistent WSGI processes (as specified in Procfile), which is exactly the scenario where a 60-second connection lifetime is suitable. AWS RDS benefits from maintaining persistent connection pooling with health checks enabled (CONN_HEALTH_CHECKS: True), and your configuration properly handles this with appropriate connection timeout settings.

Comment on lines +107 to +115
# Connection pooling - reuse connections between requests
"CONN_MAX_AGE": 60, # Keep connections alive for 60 seconds
# Health checks (Django 4.1+) - verify connection is still valid
"CONN_HEALTH_CHECKS": True,
# Database connection options
"OPTIONS": {
"connect_timeout": 10, # Timeout for establishing connection
"options": "-c statement_timeout=30000", # 30 second query timeout
},
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Apply connection settings to dev environment for consistency.

These database connection settings are only applied to the AWS RDS (production) configuration but not to the dev configuration (lines 59-68). This creates an environment inconsistency that could mask production issues during development.

Apply this diff to add similar settings to the dev database configuration:

    DATABASES = {
        "default": {
            "NAME": env.str("DB_NAME"),
            "ENGINE": "django.db.backends.postgresql_psycopg2",
            "USER": env.str("DB_USER"),
            "PASSWORD": env.str("DB_PASSWORD"),
            "HOST": env.str("DB_HOST"),
            "PORT": env.int("DB_PORT"),
+           "CONN_MAX_AGE": 60,
+           "CONN_HEALTH_CHECKS": True,
+           "OPTIONS": {
+               "connect_timeout": 10,
+               "options": "-c statement_timeout=30000",
+           },
        }
    }

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In tcf_core/settings/base.py around lines 107-115 and the dev DB block at lines
~59-68, the connection pooling and options (CONN_MAX_AGE, CONN_HEALTH_CHECKS,
and OPTIONS with connect_timeout and options="-c statement_timeout=30000") are
only applied to production; add the same keys to the dev DATABASES['default']
configuration so dev uses identical connection settings. Update the dev DB dict
to include "CONN_MAX_AGE": 60, "CONN_HEALTH_CHECKS": True, and an "OPTIONS" dict
containing "connect_timeout": 10 and "options": "-c statement_timeout=30000" (or
merge these using an existing shared settings dict if present) and keep/update
comments to reflect the intent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants