ruby-concurrency / concurrent-ruby

Modern concurrency tools including agents, futures, promises, thread pools, supervisors, and more. Inspired by Erlang, Clojure, Scala, Go, Java, JavaScript, and classic concurrency patterns.
https://ruby-concurrency.github.io/concurrent-ruby/
Other
5.68k stars 418 forks source link

The Concurrent::Map default_proc is passed a Concurrent::Hash instead of the Concurrent::Map #993

Closed mensfeld closed 1 year ago

mensfeld commented 1 year ago

With concurrent-ruby 1.2.0 things work as expected. With 1.2.1 I get following error:

undefined method `compute_if_absent' for {}:Concurrent::Hash (NoMethodError)

relevant stacktrace:

gems/concurrent-ruby-1.2.1/lib/concurrent-ruby/concurrent/collection/map/non_concurrent_map_backend.rb:22:in `[]'

it's a divination of behaviour of map, working on repro :pray:

# Works in 1.2.0 but breaks in 1.2.1
@listeners = Concurrent::Map.new do |h, k|
  h.compute_if_absent(k) { Concurrent::Array.new }
end

@listeners[:a]
dentarg commented 1 year ago

A regression from https://github.com/ruby-concurrency/concurrent-ruby/pull/989? Yeah: https://github.com/ruby-concurrency/concurrent-ruby/pull/989/files#diff-205e0f04e361a0beb29983f5bfba8710659e00eed759c0f556881fa23ac8540d

9mm commented 1 year ago

Yikes this will teach me to update minor libs before deploying

eregon commented 1 year ago

Sorry about this bug, I'll make a release with the fix ASAP.

misdoro commented 1 year ago

Same for fetch_or_store method on the Hash:

NoMethodError: undefined method `fetch_or_store' for {}:Concurrent::Hash
          h.fetch_or_store(key, Concurrent::Map.new)
eregon commented 1 year ago

Fixed in https://github.com/ruby-concurrency/concurrent-ruby/commit/f2985bd06812f183fc1382939f7844ffdb24ba50 Released as https://github.com/ruby-concurrency/concurrent-ruby/releases/tag/v1.2.2

mensfeld commented 1 year ago

Thank you for such fast turnaround!

nijikon commented 1 year ago

That was super quick, thanks!

jcoyne commented 1 year ago

Thank you for the fix. ❤️