Skip to content

fix(backend): address database connection issues and pool exhaustion (#5496)#5628

Open
MekonMAC wants to merge 1 commit intokeephq:mainfrom
MekonMAC:fix/5496-db-connection-issues
Open

fix(backend): address database connection issues and pool exhaustion (#5496)#5628
MekonMAC wants to merge 1 commit intokeephq:mainfrom
MekonMAC:fix/5496-db-connection-issues

Conversation

@MekonMAC
Copy link
Contributor

This PR addresses critical database connection issues under high load as described in #5496.

Changes:

  1. Fixed Deferred Loader Failure: Added session.refresh(deduplication_event) in create_deduplication_event to ensure the id is populated before it's accessed for logging.
  2. Prevented 'Idle in Transaction': Added a SQLAlchemy checkout listener to perform a rollback() on connection checkout. This ensures connections are returned to the pool in a clean state and prevents sessions from being stuck in 'idle in transaction' state, which is a major cause of pool exhaustion.
  3. Optimized SQLite Performance: Enabled WAL (Write-Ahead Logging) and Normal synchronous mode for SQLite to improve concurrency and performance in local/dev environments.

These changes significantly improve the reliability of the connection pool both with direct PostgreSQL connections and when using PgBouncer.

Fixes #5496

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 15, 2026

Target branch is not in the allowed branches list.

@vercel
Copy link

vercel bot commented Feb 15, 2026

Someone is attempting to deploy a commit to the KeepHQ Team on Vercel.

A member of the Team first needs to authorize it.

@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Feb 15, 2026
@CLAassistant
Copy link

CLAassistant commented Feb 15, 2026

CLA assistant check
All committers have signed the CLA.

@dosubot dosubot bot added the Bug Something isn't working label Feb 15, 2026
@MekonMAC MekonMAC force-pushed the fix/5496-db-connection-issues branch 4 times, most recently from 6606112 to 63de819 Compare February 18, 2026 22:51
@MekonMAC MekonMAC force-pushed the fix/5496-db-connection-issues branch from 63de819 to c994c69 Compare February 19, 2026 09:49
@MekonMAC
Copy link
Contributor Author

Hi Team! It seems that the CI for this PR is failing due to some global issues in the main branch:

  1. Release JSON Schema: Failing with npm error Missing: @types/react (mismatch between package.json and lock file).
  2. Unit Tests: Failing with RecursionError: maximum recursion depth exceeded in keep/api/api.py.

Could you please take a look at these infrastructure/main-branch issues? Once fixed, I'll rebase my PR. Thanks! 🚀

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

Labels

Bug Something isn't working size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[🐛 Bug]: Critical database connection issues under high alert load

2 participants