Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

feat/msp: use pgxpool instead of pgx.Conn#62994

Merged
bobheadxi merged 2 commits into
mainfrom
msp-pgxpool
May 31, 2024
Merged

feat/msp: use pgxpool instead of pgx.Conn#62994
bobheadxi merged 2 commits into
mainfrom
msp-pgxpool

Conversation

@bobheadxi

@bobheadxi bobheadxi commented May 31, 2024

Copy link
Copy Markdown
Member

During manual testing for https://github.com/sourcegraph/sourcegraph/pull/62934, I started realizing that I would run into database errors:

failed to deallocate cached statement(s): conn busy

Turns out, pgx.Conn is meant for non-concurrent use. What we really want is a connection pool, with an off-the-shelf offering from pgxpool.

Test plan

Integration tests pass, now with more cases using t.Parallel(). Also ran a quick sanity check by hand:

sg start
for i in {1..10}; do curl --header "Content-Type: application/json" --header 'authorization: bearer $SAMS_TOKEN' --data '{"filters":[{"filter":{"is_archived":false}}]}' \
    http://localhost:6081/enterpriseportal.subscriptions.v1.SubscriptionsService/ListEnterpriseSubscriptionLicenses & ; done

Changelog

  • The MSP runtime lib/managedservicesplatform/contract.Contract's ConnectToDatabase(...) has been renamed to GetConnectionPool(...), and now returns a *pgxpool.Pool instead of a *pgx.Conn
  • The MSP runtime lib/managedservicesplatform/cloudsql helper library's Connect(...) has been renamed to GetConnectionPool(...), and now returns a *pgxpool.Pool instead of a *pgx.Conn

@bobheadxi bobheadxi requested review from a team and unknwon May 31, 2024 03:51
@cla-bot cla-bot Bot added the cla-signed label May 31, 2024

@unknwon unknwon 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.

FYI asks for a stdlib interface from pgx would give you the pool (because of the stdlib semantics).

@bobheadxi

Copy link
Copy Markdown
Member Author

This is true, but at least release registry has expressed interest in using pgx directly, and as we're a postgres-only shop I wonder if it might be better to use pgx directly

@bobheadxi bobheadxi merged commit 21bf722 into main May 31, 2024
@bobheadxi bobheadxi deleted the msp-pgxpool branch May 31, 2024 16:30
@unknwon

unknwon commented May 31, 2024

Copy link
Copy Markdown
Contributor

This is true, but at least release registry has expressed interest in using pgx directly, and as we're a postgres-only shop I wonder if it might be better to use pgx directly

I think in practice it makes no difference, just different coding patterns. With that said, 10 years ago, lib/pq was the cool kid, who knows who's the next 😉

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants