grape icon indicating copy to clipboard operation
grape copied to clipboard

Coercer's cache may contains keys that are binded to memory location.

Open ericproulx opened this issue 11 months ago • 0 comments

While looking at the Coercer's cache, I've found that some keys have a weird name. When running the specs, I've found the followings :

__[[String]]_#<Proc:0x0000ffff81c8aad8 /var/grape/spec/grape/validations/validators/coerce_validator_spec.rb:652 (lambda)>_false
__Array_#<Proc:0x0000ffff81d746b0 /var/grape/spec/grape/validations/validators/coerce_validator_spec.rb:693 (lambda)>_false
__Array_#<Proc:0x0000ffff81e168c0 /var/grape/spec/grape/validations/validators/coerce_validator_spec.rb:618 (lambda)>_false
__[String]_#<Proc:0x0000ffff81e53158 /var/grape/spec/grape/validations/validators/coerce_validator_spec.rb:635 (lambda)>_false
__Hash_#<Method: JSON.parse(source, opts=...) /usr/local/bundle/gems/ruby/3.3.0/gems/json-2.9.1/lib/json/common.rb:220>_false
__Integer_#<Proc:0x0000ffff81ef4788 /var/grape/spec/grape/validations/validators/coerce_validator_spec.rb:774 (lambda)>_false
__[Integer]_#<Proc:0x0000ffff8209a7b8 /var/grape/spec/grape/validations/validators/coerce_validator_spec.rb:676 (lambda)>_false
__Integer_#<Proc:0x0000ffff821b1b10 /var/grape/spec/grape/validations/validators/coerce_validator_spec.rb:835 (lambda)>_false
__Integer_#<Proc:0x0000ffff83295008 /var/grape/spec/grape/validations/validators/coerce_validator_spec.rb:835 (lambda)>_false
__Integer_#<Proc:0x0000ffff87ade300 /var/grape/spec/grape/validations/validators/coerce_validator_spec.rb:835 (lambda)>_false
__Integer_#<Proc:0x0000ffff83324168 /var/grape/spec/grape/validations/validators/coerce_validator_spec.rb:797 (lambda)>_false
__Integer_#<Proc:0x0000ffff8301aff8 /var/grape/spec/grape/validations/validators/coerce_validator_spec.rb:797 (lambda)>_false
__Integer_#<Proc:0x0000ffff83159e50 /var/grape/spec/grape/validations/validators/coerce_validator_spec.rb:797 (lambda)>_false
__Array_#<Proc:0x0000ffff8216a468 /var/grape/spec/grape/validations/validators/coerce_validator_spec.rb:711 (lambda)>_false
__Array_#<Proc:0x0000ffff82030d68 /var/grape/spec/grape/validations/validators/coerce_validator_spec.rb:711 (lambda)>_false
__Array_#<Proc:0x0000ffff82095808 /var/grape/spec/grape/validations/validators/coerce_validator_spec.rb:711 (lambda)>_false
__[Grape::API::Boolean, String]_#<Proc:0x0000ffff81c4aa78 /var/grape/spec/grape/validations/validators/coerce_validator_spec.rb:82 (lambda)>_false
__[Grape::API::Boolean, String]_#<Proc:0x0000ffff81c91d60 /var/grape/spec/grape/validations/validators/coerce_validator_spec.rb:82 (lambda)>_false
__[Grape::API::Boolean, String]_#<Proc:0x0000ffff81ce0c58 /var/grape/spec/grape/validations/validators/coerce_validator_spec.rb:82 (lambda)>_false
__[Grape::API::Boolean, String]_#<Proc:0x0000ffff81e53108 /var/grape/spec/grape/validations/validators/coerce_validator_spec.rb:1129 (lambda)>_false
__[Grape::API::Boolean, String]_#<Proc:0x0000ffff81ea4800 /var/grape/spec/grape/validations/validators/coerce_validator_spec.rb:1129 (lambda)>_false
__[Grape::API::Boolean, String]_#<Proc:0x0000ffff81f155c8 /var/grape/spec/grape/validations/validators/coerce_validator_spec.rb:1129 (lambda)>_false
__String_#<Proc:0x0000ffff81f221d8(&:strip) (lambda)>_false

It seems to leak like that since we have different memory address for the same location but its just because its different tests. I've tested it on a web server with a single process with 5 threads and the memory address stays the same.

I think we can do better and probably warm the cache during the compilation time instead of the runtime. That would save some synchronization with the threads when warming it.

ericproulx avatar Dec 19 '24 22:12 ericproulx