Skip to content

Commit

Permalink
refactoring class-hash to be ractor-safe
Browse files Browse the repository at this point in the history
mutable constants can't be shared across ractors; this changes that design to define the required variables as constants on the Resource class, which makes them reachable using ractors; the ClassHash is kept in order not to break integrations relying on its existence, but under the hood it's doing the same thing
  • Loading branch information
HoneyryderChuck committed Nov 17, 2024
1 parent 3cf932e commit fc34b8a
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/resolv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2107,7 +2107,14 @@ class Resource < Query

attr_reader :ttl

ClassHash = {} # :nodoc:
ClassHash = Module.new do
module_function

def []=(type_class_value, klass)
type_value, class_value = type_class_value
Resource.const_set(:"Type#{type_value}_Class#{class_value}", klass)
end
end

def encode_rdata(msg) # :nodoc:
raise NotImplementedError.new
Expand Down Expand Up @@ -2145,7 +2152,9 @@ def hash # :nodoc:
end

def self.get_class(type_value, class_value) # :nodoc:
return ClassHash[[type_value, class_value]] ||
cache = :"Type#{type_value}_Class#{class_value}"

return (const_defined?(cache) && const_get(cache)) ||
Generic.create(type_value, class_value)
end

Expand Down

0 comments on commit fc34b8a

Please sign in to comment.