From 03f1abfcc3e43fce188f94a770f5f7b6af6f36b5 Mon Sep 17 00:00:00 2001
From: Lin Jen-Shin <godfat@godfat.org>
Date: Tue, 14 Feb 2017 13:48:13 +0800
Subject: [PATCH] Only ensure against yield so that pool should be available

Feedback:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/9192#note_23293693
---
 lib/gitlab/database.rb | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/lib/gitlab/database.rb b/lib/gitlab/database.rb
index e6612bc3aad..a6e9ea3dead 100644
--- a/lib/gitlab/database.rb
+++ b/lib/gitlab/database.rb
@@ -72,10 +72,11 @@ module Gitlab
     def self.with_connection_pool(pool_size)
       pool = create_connection_pool(pool_size)
 
-      yield(pool)
-
-    ensure
-      pool.disconnect!
+      begin
+        yield(pool)
+      ensure
+        pool.disconnect!
+      end
     end
 
     def self.create_connection_pool(pool_size)
-- 
GitLab