Skip to content

fix(webapp): reuse the primary db pool for legacy run-ops when DSNs match#4253

Merged
d-cs merged 2 commits into
mainfrom
feat/run-ops-connection-pool-split
Jul 14, 2026
Merged

fix(webapp): reuse the primary db pool for legacy run-ops when DSNs match#4253
d-cs merged 2 commits into
mainfrom
feat/run-ops-connection-pool-split

Conversation

@d-cs

@d-cs d-cs commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Summary

When the run-ops split is enabled, the legacy run-ops database client was always constructed as its own connection pool, even when it points at the same database as the primary (control-plane) client. On setups where those two DSNs resolve to the same physical database, this opened a second, redundant pool and doubled the number of connections used against that database. This change makes the legacy client reuse the primary client's pool whenever their DSNs point at the same database, and only open a separate pool when they genuinely differ.

Fix

A small sameDatabaseTarget comparison (host, port, database name, user) decides whether the legacy DSN points at the same database as the primary. When it does, the legacy handle reuses the primary client by reference, so no second pool is opened. When the DSNs diverge, the legacy client is built independently as before, so the split still works once the databases are actually separate.

Two smaller changes ride along:

  • An optional per-pool limit for the run-ops read replica, which connects unpooled and so draws raw backend connections; unset, it falls back to the existing default and behaviour is unchanged.
  • A startup warning about a missing legacy replica URL is now suppressed when the legacy client shares the primary pool, where it would be misleading.

Verification

Booted the webapp end-to-end in three modes and confirmed the pools opened as expected via the client's own startup logs and live backend connection counts: split off (single pool), split on with a shared database (legacy reuses the primary pool, no doubling), and split on with separate databases (legacy opens its own pool).

…atch

When the run-ops split is enabled, the legacy run-ops Prisma client was
always built as its own connection pool, even when it targeted the same
physical database as the primary (control-plane) client. Where those DSNs
resolve to the same database, that opened a second, redundant pool and
doubled the connections used against that database.

Reuse the primary client by reference when the legacy and primary DSNs
resolve to the same database (host, port, database name, user), and only
build a separate legacy pool when they genuinely differ.
@changeset-bot

changeset-bot Bot commented Jul 14, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 6c4eed0

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@d-cs d-cs self-assigned this Jul 14, 2026
@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Run-ops topology selection now compares effective legacy and control-plane database targets. When they match, legacy run-ops reuse the control-plane clients; otherwise, independent legacy clients are created. A separate environment setting controls the new run-ops replica connection limit. Tests cover URL comparison, aliasing, independent clients, PostgreSQL queries, and cleanup. Documentation records the shared-pool behavior.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the change and verification, but it misses required template sections like Closes #, checklist, Testing, Changelog, and Screenshots. Add the required template sections: Closes #issue, checklist items, a Testing section with steps run, a Changelog summary, and Screenshots if applicable.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the main change: reusing the primary db pool for legacy run-ops when DSNs match.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/run-ops-connection-pool-split

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.

@d-cs d-cs marked this pull request as ready for review July 14, 2026 10:05

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

@d-cs d-cs merged commit a1ca646 into main Jul 14, 2026
32 of 33 checks passed
@d-cs d-cs deleted the feat/run-ops-connection-pool-split branch July 14, 2026 10:20
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.

2 participants