[go: up one dir, main page]

Skip to content

Clean up connection pool in database_replica specs

What does this MR do and why?

Fixes a connection pool leak in the :database_replica rspec decorator.

Before this change, the connection pools created for each test were never disconnected, so each test wrapped in :database_replica would permenantly reserve 1 connection per database for the lifetime of the rspec session.

References

I found this while working on Extract Load Balancer code to a gem (#544027).

How to set up and validate locally

I found this while running spec/lib/gitlab/database/load_balancing_spec.rb, since that spec runs a lot of :database_replica specs.

  1. Open a psql console with gdk psql
  2. In the psql console, count how many connections your database has: select count(*) from pg_stat_activity where backend_type = 'client backend';
  3. Start psql running the previous command in a loop: \watch 1 (no semicolon)
  4. Run spec/lib/gitlab/database/load_balancing_spec.rb, either with or without this change. Observe the connection counts growing without bound without this change, while they level out with this change.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Merge request reports

Loading