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