Skip to content

Commit

Permalink
Make registry fully thread safe
Browse files Browse the repository at this point in the history
Without this change potential incrementation can "go away" and can actually mismatch by 1 if run in multiple threads the same time. This can lead to super weird errors where counter is not as expected (been there, took me ages to debug).

ref: ruby-concurrency/concurrent-ruby#970
  • Loading branch information
mensfeld committed Nov 20, 2022
1 parent 079c1f9 commit d193c0e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rom/factory/sequences.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def next(key)

# @api private
def reset
@registry = Concurrent::Map.new { |h, k| h[k] = 0 }
@registry = Concurrent::Map.new { |h, k| h.compute_if_absent(k) { 0 } }
self
end
end
Expand Down

0 comments on commit d193c0e

Please sign in to comment.