-
Notifications
You must be signed in to change notification settings - Fork 6
Handle custom reset semantics #3
Description
Given we have a connection object, that could raise some ConnectionError documented usage of simple_circuit_breaker would be:
circuit_breaker.handle(ConnectionError) { connection.do_things }which on first fail usually invalidate connection object. That means all subsequent calls will definitely fail even if connectivity to service in question was restored.
One solution one can consider is:
circuit_breaker.handle(ConnectionError) do
Connection.new.do_things
endwhich will defeat the problem, but not very effective in terms of resources, and actually will create new one: Under high load connections will be opened faster than closed by garbage collector, that could cause problems, like "Maximum number of connections reached" which can make actual downtime (Happened to redis server once for me).
So is there a proper way to re-use a connection object, but create new one (ie reset it) when circuit breaker goes to half open state?
Probably something along these lines:
circuit_breaker.on_reset { connection = connection_pool.fetch_one }
# ...
circuit_breaker.handle(ConnectionError) { connection.do_things }WDYT?