Add ConnectionRefused exception

* required to fix retry+connection initialization corner case.
This commit is contained in:
Brian J. Cardiff 2016-12-15 14:40:56 -03:00
parent 4c74e6c9da
commit 2ca60ba43f
2 changed files with 13 additions and 0 deletions

View file

@ -11,6 +11,9 @@ module DB
class PoolRetryAttemptsExceeded < Error class PoolRetryAttemptsExceeded < Error
end 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 class ConnectionLost < Error
getter connection : Connection getter connection : Connection
@ -18,6 +21,12 @@ module DB
end end
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 class Rollback < Exception
end end
end end

View file

@ -93,6 +93,10 @@ module DB
# and remove it from the known pool. # and remove it from the known pool.
delete(e.connection) delete(e.connection)
e.connection.close 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
end end
raise PoolRetryAttemptsExceeded.new raise PoolRetryAttemptsExceeded.new