Skip to content

Handle custom reset semantics #3

@waterlink

Description

@waterlink

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions