Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle custom reset semantics #3

Open
waterlink opened this issue Jan 29, 2015 · 1 comment
Open

Handle custom reset semantics #3

waterlink opened this issue Jan 29, 2015 · 1 comment

Comments

@waterlink
Copy link

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
end

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

@waterlink
Copy link
Author

or probably on_half_open right before CB retries to enter open state

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant