Skip to content

ActiveSupportCacheStore: race_condition_ttl is a silent no-op (missing assignment) #992

@plantoeat

Description

@plantoeat

Summary

In Flipper::Adapters::ActiveSupportCacheStore#write_options, the race_condition_ttl option is never actually passed to @cache.fetch / @cache.write because the assignment operator is missing. The option has been silently broken since it was introduced in #932.

Location

lib/flipper/adapters/active_support_cache_store.rb#L78-L83 on main:

def write_options
  write_options = {}
  write_options[:expires_in] = @ttl if @ttl
  write_options[:race_condition_ttl] if @race_condition_ttl   # ← no-op
  write_options
end

The third line reads write_options[:race_condition_ttl] (which returns nil on a freshly-created empty hash with no default) and discards the result. It should be:

write_options[:race_condition_ttl] = @race_condition_ttl if @race_condition_ttl

Impact

Anyone configuring the adapter with race_condition_ttl: gets the option accepted without error and exposed via the race_condition_ttl reader, but it never reaches ActiveSupport::Cache::Store. The thundering-herd protection users expect from race_condition_ttl is not actually in effect.

How it slipped through

#932 added both the feature and the bug in a single commit. The accompanying specs in spec/flipper/adapters/active_support_cache_store_spec.rb only assert that the constructor sets the reader (expect(adapter.race_condition_ttl).to eq(race_condition_ttl)). There's no behavioral test that @cache.fetch / @cache.write actually receives race_condition_ttl in its options hash, so the typo wasn't caught.

Proposed fix

  1. Add the missing = @race_condition_ttl in write_options.
  2. Add a spec that stubs cache.fetch (or uses a cache double) and asserts the options hash includes race_condition_ttl: <value> when the adapter was constructed with one.

Happy to open a PR for this if it'd be helpful.

How it was found

Caught by Cursor Bugbot during review of a downstream PR that vendors this adapter file. I verified against main that the bug is still present.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions