Skip to content

Fix MultiStore .close to skip if no connections borrowed

Sylvester Chin requested to merge sc1-fix-multistore-close into master

What does this MR do and why?

This MR updates the MultiStore .close method to skip if no connections borrowed. This prevents any connection borrowing, which triggers instrumentation logic, from being called post-fork in https://github.com/mperham/connection_pool/blob/v2.4.1/lib/connection_pool.rb#L63

See more details in #367527 (comment 1734048448)

Note that !142042 (merged) also fixes the problem of incorrect pid labels.

MR acceptance checklist

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

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

  1. Enable the web exporter in the local setup (https://gitlab.com/gitlab-org/gitlab/-/blob/f98a03e1407d6f3b5cb5716a2c12f6b456465e47/config/gitlab.yml.example#L1336)

  2. Verify that the metrics contains labels form both puma_1 and puma_0. You may need to click around the web interface.

➜  gitlab git:(sc1-fix-multistore-close) ✗ curl -s localhost:8083/metrics | grep gitlab_connection
# HELP gitlab_connection_pool_available_count Multiprocess metric
# TYPE gitlab_connection_pool_available_count gauge
gitlab_connection_pool_available_count{connection_class="Gitlab::Redis::MultiStore",pool_key="pool-39400",pool_name="",pid="puma_1"} 17
gitlab_connection_pool_available_count{connection_class="Redis",pool_key="pool-121700",pool_name="sessions",pid="puma_1"} 17
gitlab_connection_pool_available_count{connection_class="Redis",pool_key="pool-126060",pool_name="shared_state",pid="puma_1"} 17
gitlab_connection_pool_available_count{connection_class="Redis",pool_key="pool-184200",pool_name="cache",pid="puma_0"} 17
gitlab_connection_pool_available_count{connection_class="Redis",pool_key="pool-221500",pool_name="sessions",pid="puma_0"} 17
gitlab_connection_pool_available_count{connection_class="Redis",pool_key="pool-221520",pool_name="sessions",pid="puma_0"} 17
gitlab_connection_pool_available_count{connection_class="Redis",pool_key="pool-221540",pool_name="shared_state",pid="puma_0"} 17
gitlab_connection_pool_available_count{connection_class="Redis",pool_key="pool-25720",pool_name="",pid="puma_0"} 17
gitlab_connection_pool_available_count{connection_class="Redis",pool_key="pool-25720",pool_name="",pid="puma_1"} 17
gitlab_connection_pool_available_count{connection_class="Redis",pool_key="pool-804480",pool_name="cache",pid="puma_1"} 17
gitlab_connection_pool_available_count{connection_class="Redis",pool_key="pool-83420",pool_name="",pid="puma_1"} 17
gitlab_connection_pool_available_count{connection_class="Redis",pool_key="pool-841520",pool_name="sessions",pid="puma_1"} 17
gitlab_connection_pool_available_count{connection_class="Redis",pool_key="pool-841540",pool_name="shared_state",pid="puma_1"} 17
# HELP gitlab_connection_pool_size Multiprocess metric
# TYPE gitlab_connection_pool_size gauge
gitlab_connection_pool_size{connection_class="Gitlab::Redis::MultiStore",pool_key="pool-39400",pool_name="",pid="puma_1"} 18
gitlab_connection_pool_size{connection_class="Redis",pool_key="pool-121700",pool_name="sessions",pid="puma_1"} 18
gitlab_connection_pool_size{connection_class="Redis",pool_key="pool-126060",pool_name="shared_state",pid="puma_1"} 18
gitlab_connection_pool_size{connection_class="Redis",pool_key="pool-184200",pool_name="cache",pid="puma_0"} 18
gitlab_connection_pool_size{connection_class="Redis",pool_key="pool-221500",pool_name="sessions",pid="puma_0"} 18
gitlab_connection_pool_size{connection_class="Redis",pool_key="pool-221520",pool_name="sessions",pid="puma_0"} 18
gitlab_connection_pool_size{connection_class="Redis",pool_key="pool-221540",pool_name="shared_state",pid="puma_0"} 18
gitlab_connection_pool_size{connection_class="Redis",pool_key="pool-25720",pool_name="",pid="puma_0"} 18
gitlab_connection_pool_size{connection_class="Redis",pool_key="pool-25720",pool_name="",pid="puma_1"} 18
gitlab_connection_pool_size{connection_class="Redis",pool_key="pool-804480",pool_name="cache",pid="puma_1"} 18
gitlab_connection_pool_size{connection_class="Redis",pool_key="pool-83420",pool_name="",pid="puma_1"} 18
gitlab_connection_pool_size{connection_class="Redis",pool_key="pool-841520",pool_name="sessions",pid="puma_1"} 18
gitlab_connection_pool_size{connection_class="Redis",pool_key="pool-841540",pool_name="shared_state",pid="puma_1"} 18

Numbered steps to set up and validate the change are strongly suggested.

Edited by Sylvester Chin

Merge request reports