-
Notifications
You must be signed in to change notification settings - Fork 6
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
handler (storage) thread-safety #5
Conversation
…ved concurrency) this is mostly a safe-bet ... without additional code the mixin is not fully thread-safe!
also use https source
@@ -18,6 +18,8 @@ Gem::Specification.new do |s| | |||
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } | |||
s.require_paths = ["lib"] | |||
|
|||
s.add_dependency 'thread_safe', ["~> 0.3"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kares Sorry for being very slow on my end. Question for you, should this be [">= 0.3.4"]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when I originally did this 0.3.x was latest - was probably afraid that it might broke around 1.0
but since thread_safe is dead and part of concurrent_ruby gem, latest (last) release is 0.3.5.
so this shouldn't matter much really - but I update to make sure < 0.3.4 is not used - thanks.
Thanks very much @kares. I think this looks great 👍 @benlangfeld could you take a look when you get a chance? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please include a changelog entry? Other than that, this looks good.
Awesome! Thank you both! |
* concurrent-ruby: [CI] let's test against more (recent) Rubies use concurrent/map as a thread_safe replacement ~~handler (storage) thread-safety (adhearsion#5)~~
HGH's design is not thread-safe since most of the use-cases are actors themselves - thus protected from concurrent access. However, not all and esp. under JRuby (with non-GIL concurrency and likely due threaded fibers) some parts tend to break unexpectedly when a handler update is executed by 2 threads.
Here's a failure from the older stack which is still relevant today (with an updated Adhearsion 2.6 stack) :
@handlers ||= Hash.new { |h, k| h[k] = Hash.new { |h, k| h[k] = [] } }
the underlying issue is that when the same key is "missed" (under 2 threads) the default proc might execute twice ... withTS::Cache
there's an atomic guarantee offetch_or_store
method - once set we're only retrieve the same value for the given keyp.s.
ThreadSafe::Cache
is part of the concurrent-ruby gem these days, if there's interest in getting the changes upstream it should be straightforward to migrate usingConcurrent::Hash
instead.