Skip to content

Cached flags collide between two client instances on different environments (OkHttp cache not namespaced per environment) #85

Description

@adamvialpando

When two Flagsmith client instances run in the same app on different environment keys with caching enabled, they can serve or overwrite each other's cached flags.

Use case: a host app uses the Flagsmith Android SDK, and a third party SDK embedded in the same app also uses the Flagsmith SDK, each configured with its own environment key against the same base URL.

Observed behaviour: with caching on, flags from one environment can be returned for the other, or the two instances overwrite each other's cached values.

Likely cause (to validate): the OkHttp cache at context.cacheDir keys entries on request URL only. The environment is sent as the X-Environment-Key header and the flags path is fixed, so two instances on the same base URL share cached responses. Unlike iOS there is no shared singleton, but the on disk cache is not environment namespaced.

Steps to reproduce:

  1. Create two Flagsmith clients in one app, each with a different environment key, same API base URL, caching enabled.
  2. Fetch flags on client A, then client B.
  3. Observe client B serving client A's cached flags, or the two overwriting each other.

Proposed direction: namespace the cache per environment key (separate cache dir or environment scoped cache key) so instances don't collide

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions