You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 15, 2022. It is now read-only.
By the time `elsif !key?(key)` is called another thread might have
created a `key` mapping, then `!key?(key)` check would then fail
resulting in `[]` returning `nil` an incorrect `value`.
This is most likely to be triggered by a code like this:
ThreadSafe::Cache.new {|cache, key| cache[key] = some_value}
Related: rails/rails#13961.
ifvalue=super# non-falsy value is an existing mapping, return it right away
39
39
value
40
-
elsif@default_proc && !key?(key)
40
+
# re-check is done with get_or_default(key, NULL) instead of a simple !key?(key) in order to avoid a race condition, whereby by the time the current thread gets to the key?(key) call
41
+
# a key => value mapping might have already been created by a different thread (key?(key) would then return true, this elsif branch wouldn't be taken and an incorrent +nil+ value
42
+
# would be returned)
43
+
# note: nil == value check is not technically necessary
44
+
elsif@default_proc && nil == value && NULL == (value=get_or_default(key,NULL))
0 commit comments