Skip to content

Commit

Permalink
fix: avoid reusing instances for classes reloaded in development
Browse files Browse the repository at this point in the history
This only affects development, when using threaded servers like Puma
AND with concurrency enabled.

The bug manifests as serializers "not being updated", and the cause is
that  even though the class itself is being reloaded correctly, the
`instance` method will a previously cached instance of a previous
version of the class.

By using `object_id`, if the class was reloaded, a new instance will be
created.
  • Loading branch information
ElMassimo committed Mar 1, 2023
1 parent e69ae08 commit 0bd928d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/oj_serializers/serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ def instance
# Internal: Cache key to set a thread-local instance.
def instance_key
unless defined?(@instance_key)
@instance_key = "#{name.underscore}_instance".to_sym
@instance_key = "#{name.underscore}_instance_#{object_id}".to_sym
# We take advantage of the fact that this method will always be called
# before instantiating a serializer to define the write_to_json method.
class_eval(write_to_json_body)
Expand Down

0 comments on commit 0bd928d

Please sign in to comment.