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
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

View File

@ -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