Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 16, 2025

PostgreSQL was hitting max connection limits with OperationalError: FATAL: no more connections allowed (max_client_conn) on organization pages. The application was configured with CONN_MAX_AGE = 0, causing Django to open and close a fresh connection for every request.

Changes

Updated connection pooling configuration in blt/settings.py:

  • Set CONN_MAX_AGE = 600 (was 0)
  • Updated dj_database_url.config(conn_max_age=600) in both initialization and database configuration (was 0 and 500 respectively)
# Before: New connection per request
CONN_MAX_AGE = 0
DATABASES["default"] = dj_database_url.config(conn_max_age=0, ssl_require=False)

# After: Persistent connections for 10 minutes
CONN_MAX_AGE = 600
DATABASES["default"] = dj_database_url.config(conn_max_age=600, ssl_require=False)

Connections are now reused across requests and aged out after 10 minutes of inactivity.

Original prompt

Exception Type: OperationalError at /organization/cassandraslee/
Exception Value: connection to server at "127.0.0.1", port 6000 failed: FATAL: no more connections allowed (max_client_conn)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 16, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.


Note

Free review on us!

CodeRabbit is offering free reviews until Wed Dec 17 2025 to showcase some of the refinements we've made.

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

Copilot AI and others added 2 commits December 16, 2025 17:05
- Set CONN_MAX_AGE to 600 seconds (10 minutes)
- Update dj_database_url.config() to use conn_max_age=600
- Add comments explaining the fix
- Prevents "no more connections allowed (max_client_conn)" errors

Co-authored-by: DonnieBLT <[email protected]>
Address code review feedback by adding comment explaining that
db_from_env is checked later in settings.py to determine database
configuration.

Co-authored-by: DonnieBLT <[email protected]>
Copilot AI changed the title [WIP] Fix operational error for max client connections Fix database connection exhaustion by enabling persistent connections Dec 16, 2025
Copilot AI requested a review from DonnieBLT December 16, 2025 17:10
@DonnieBLT DonnieBLT marked this pull request as ready for review December 16, 2025 17:16
Copilot AI review requested due to automatic review settings December 16, 2025 17:16
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes database connection exhaustion issues by enabling persistent connection pooling in Django. The application was previously opening a new database connection for every request (CONN_MAX_AGE = 0), which caused PostgreSQL to hit its maximum connection limit.

Key Changes:

  • Set CONN_MAX_AGE to 600 seconds (10 minutes) to enable connection pooling
  • Updated all dj_database_url.config() calls to use consistent conn_max_age=600 parameter
  • Added explanatory comments documenting the connection pooling configuration

@github-actions github-actions bot added the pre-commit: passed Pre-commit checks passed label Dec 16, 2025
@github-project-automation github-project-automation bot moved this from Backlog to Ready in 📌 OWASP BLT Project Board Dec 16, 2025
@github-actions
Copy link
Contributor

👋 Hi @Copilot!

This pull request needs a peer review before it can be merged. Please request a review from a team member who is not:

  • The PR author
  • DonnieBLT
  • coderabbitai
  • copilot

Once a valid peer review is submitted, this check will pass automatically. Thank you!

@github-actions github-actions bot added needs-peer-review PR needs peer review tests: passed Django tests passed last-active: 0d PR last updated 0 days ago last-active: 2d PR last updated 2 days ago and removed last-active: 0d PR last updated 0 days ago labels Dec 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

files-changed: 1 last-active: 2d PR last updated 2 days ago needs-peer-review PR needs peer review pre-commit: passed Pre-commit checks passed tests: passed Django tests passed

Projects

Status: Ready

Development

Successfully merging this pull request may close these issues.

2 participants