mirror of
https://github.com/discourse/discourse.git
synced 2025-01-19 03:22:46 +08:00
d5cd669464
When using `Discourse.cache.fetch` with an expiry, there's a potential for a race condition due to how we read the data from redis. The code used to be ```ruby raw = redis.get(key) if !force entry = read_entry(key) if raw return entry if raw && !(entry == :__corrupt_cache__) ``` with `read_entry` defined as follow ```ruby def read_entry(key) if data = redis.get(key) Marshal.load(data) end rescue => e :__corrupt_cache__ end ``` If the value at "key" expired in redis between `raw = redis.get` and `entry = read_entry`, the `entry` variable would be `nil` despite `raw` having a value. We would then proceed to return `entry` (which is `nil`) thinking it had a value, when it didn't. The first `redis.get` can be skipped altogether and we can rely only on `read_entry` to read the data from redis. Thus avoiding the race condition and removing the double read operations. Internal ref - t/132507 |
||
---|---|---|
.. | ||
fabricators | ||
fixtures | ||
generator | ||
helpers | ||
import_export | ||
initializers | ||
integration | ||
integrity | ||
jobs | ||
lib | ||
mailers | ||
migrations | ||
models | ||
multisite | ||
requests | ||
script/import_scripts | ||
serializers | ||
services | ||
support | ||
system | ||
tasks | ||
views | ||
rails_helper.rb | ||
regenerate_swagger_docs | ||
swagger_helper.rb |