From 2ca60ba43f29d65eda60a9930f92267957717b88 Mon Sep 17 00:00:00 2001 From: "Brian J. Cardiff" Date: Thu, 15 Dec 2016 14:40:56 -0300 Subject: [PATCH] Add ConnectionRefused exception * required to fix retry+connection initialization corner case. --- src/db/error.cr | 9 +++++++++ src/db/pool.cr | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/src/db/error.cr b/src/db/error.cr index 98ab795..8f0425a 100644 --- a/src/db/error.cr +++ b/src/db/error.cr @@ -11,6 +11,9 @@ module DB class PoolRetryAttemptsExceeded < Error end + # Raised when an established connection is lost + # probably due to socket/network issues. + # It is used by the connection pool retry logic. class ConnectionLost < Error getter connection : Connection @@ -18,6 +21,12 @@ module DB end end + # Raised when a connection is unable to be established + # probably due to socket/network or configuration issues. + # It is used by the connection pool retry logic. + class ConnectionRefused < Error + end + class Rollback < Exception end end diff --git a/src/db/pool.cr b/src/db/pool.cr index 6566b32..ada556d 100644 --- a/src/db/pool.cr +++ b/src/db/pool.cr @@ -93,6 +93,10 @@ module DB # and remove it from the known pool. delete(e.connection) e.connection.close + rescue e : ConnectionRefused + # a ConnectionRefused means a new connection + # was intented to be created + # nothing to due but to retry soon end end raise PoolRetryAttemptsExceeded.new