Fix ActiveRecord connection leaks
This ensures we're not leaking ActiveRecord connection objects left and right, mainly when running code in Sidekiq.
Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/27949, fixes https://gitlab.com/gitlab-com/infrastructure/issues/1139