prognostikos / cb2 Goto Github PK
View Code? Open in Web Editor NEWImplementation of the circuit breaker pattern in Ruby, backed by Redis
License: MIT License
Implementation of the circuit breaker pattern in Ruby, backed by Redis
License: MIT License
Hi
It looks like CB2 can never become fully closed after being opened once. Here's a failing test.
The rolling window strategy's #half_open?
is pretty much the opposite of #open?
, which is not what it is supposed to represent.
I was thinking of having a success
callback in a strategy, which would reset last_open
if the circuit breaker is currently half-open. This would solve the issue in a single-threaded case, although in a hacky manner, but there are going to be issues with concurrent clients (cranking up number of WORKERS
in the test to 50 or so exposes the issue).
Ok, so I got somewhat weird behaviour regarding the redis connection. Whenever I want to run something inside the breaker block, I get a SocketError (see stack trace below).
Manually creating a redis connection with the same url works fine and allows me to save things to redis...
Comparing the two redis connections tells me that they are the same:
# manual redis
my_redis = Redis.new
my_redis
=> #<Redis client v3.3.1 for redis://<redacted_but_correct_url>.com:6379/0>
my_redis.set('totally', 'works')
=> "OK"
# cb2 breaker redis
breaker ||= CB2::Breaker.new(
...,
redis: Redis.new
)
breaker
=> <... @redis=#<Redis client v3.3.1 for redis://<redacted_but_correct_url>.com:6379/0>, @last_open=nil>>
Any thoughts? Ideas?
Error output:
SocketError: getaddrinfo: Name or service not known
from /usr/local/rvm/gems/ruby-2.3.1/gems/redis-3.3.1/lib/redis/connection/ruby.rb:212:in `getaddrinfo'
from /usr/local/rvm/gems/ruby-2.3.1/gems/redis-3.3.1/lib/redis/connection/ruby.rb:212:in `connect'
from /usr/local/rvm/gems/ruby-2.3.1/gems/redis-3.3.1/lib/redis/connection/ruby.rb:295:in `connect'
from /usr/local/rvm/gems/ruby-2.3.1/gems/redis-3.3.1/lib/redis/client.rb:336:in `establish_connection'
from /usr/local/rvm/gems/ruby-2.3.1/gems/redis-3.3.1/lib/redis/client.rb:101:in `block in connect'
from /usr/local/rvm/gems/ruby-2.3.1/gems/redis-3.3.1/lib/redis/client.rb:293:in `with_reconnect'
from /usr/local/rvm/gems/ruby-2.3.1/gems/redis-3.3.1/lib/redis/client.rb:100:in `connect'
from /usr/local/rvm/gems/ruby-2.3.1/gems/redis-3.3.1/lib/redis/client.rb:364:in `ensure_connected'
from /usr/local/rvm/gems/ruby-2.3.1/gems/redis-3.3.1/lib/redis/client.rb:221:in `block in process'
from /usr/local/rvm/gems/ruby-2.3.1/gems/redis-3.3.1/lib/redis/client.rb:306:in `logging'
from /usr/local/rvm/gems/ruby-2.3.1/gems/redis-3.3.1/lib/redis/client.rb:220:in `process'
from /usr/local/rvm/gems/ruby-2.3.1/gems/redis-3.3.1/lib/redis/client.rb:120:in `call'
from /usr/local/rvm/gems/ruby-2.3.1/gems/redis-3.3.1/lib/redis/client.rb:572:in `block in resolve_master'
from /usr/local/rvm/gems/ruby-2.3.1/gems/redis-3.3.1/lib/redis/client.rb:554:in `block in sentinel_detect'
from /usr/local/rvm/gems/ruby-2.3.1/gems/redis-3.3.1/lib/redis/client.rb:546:in `each'
from /usr/local/rvm/gems/ruby-2.3.1/gems/redis-3.3.1/lib/redis/client.rb:546:in `sentinel_detect'
... 22 levels...
from /usr/local/rvm/gems/ruby-2.3.1@global/gems/bundler-1.12.1/lib/bundler/cli/exec.rb:63:in `load'
from /usr/local/rvm/gems/ruby-2.3.1@global/gems/bundler-1.12.1/lib/bundler/cli/exec.rb:63:in `kernel_load'
from /usr/local/rvm/gems/ruby-2.3.1@global/gems/bundler-1.12.1/lib/bundler/cli/exec.rb:24:in `run'
from /usr/local/rvm/gems/ruby-2.3.1@global/gems/bundler-1.12.1/lib/bundler/cli.rb:304:in `exec'
from /usr/local/rvm/gems/ruby-2.3.1@global/gems/bundler-1.12.1/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
from /usr/local/rvm/gems/ruby-2.3.1@global/gems/bundler-1.12.1/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
from /usr/local/rvm/gems/ruby-2.3.1@global/gems/bundler-1.12.1/lib/bundler/vendor/thor/lib/thor.rb:359:in `dispatch'
from /usr/local/rvm/gems/ruby-2.3.1@global/gems/bundler-1.12.1/lib/bundler/vendor/thor/lib/thor/base.rb:440:in `start'
from /usr/local/rvm/gems/ruby-2.3.1@global/gems/bundler-1.12.1/lib/bundler/cli.rb:11:in `start'
from /usr/local/rvm/gems/ruby-2.3.1@global/gems/bundler-1.12.1/exe/bundle:27:in `block in <top (required)>'
from /usr/local/rvm/gems/ruby-2.3.1@global/gems/bundler-1.12.1/lib/bundler/friendly_errors.rb:98:in `with_friendly_errors'
from /usr/local/rvm/gems/ruby-2.3.1@global/gems/bundler-1.12.1/exe/bundle:19:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.3.1@global/bin/bundle:23:in `load'
from /usr/local/rvm/gems/ruby-2.3.1@global/bin/bundle:23:in `<main>'
from /usr/local/rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `eval'
from /usr/local/rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `<main>'
FWIW, I am maintaining a fork at https://github.com/prognostikos/cb2 as we use this in production.
I'd be happy to take over the gem if that's an option, or otherwise contribute back to this repo with PRs etc.
Hi @pedro! Any plans to support Redis 4? I see that at the moment it's only 3.x support.
what is the current state of this gem?
the last commit dates from a year ago...is it still maintained or its just "done"?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.