Skip to content

fluree.db() can serve a stale cached view after subsequent commits (read-your-writes violation) #1330

Closed

Description

@bplatz

Problem

Calling fluree.db(ledger_id) after committing additional transactions can return a previously cached GraphDb view that predates those commits. Observed twice while writing integration tests, in both ledger-manager configurations:

  1. FlureeBuilder::memory().with_ledger_cache_config(LedgerManagerConfig::default()) + background indexer: after trigger_index_and_wait_outcome, two further commits (verified receipt.ledger.t() == 3), then fluree.db(ledger_id) returned a view with snapshot.t == 1 — neither commit visible (it_cyclic_bgp_probe.rs, phase 2).
  2. Plain FlureeBuilder::memory().build_memory() + synchronous fluree.reindex(...): the second fluree.db() call in a test (after an earlier call had populated the cache, followed by more commits) served the pre-commit view; even a post-reindex fluree.db() reported t = 1 while the data was at t = 5 (it_join_batched_overlay.rs::batched_join_decimal_novelty).

Both tests work around it by pinning explicitly: fluree.db_at_t(ledger_id, receipt.ledger.t()) — the workaround sites are marked with comments ("a cached pre-commit view can otherwise serve").

Why it matters beyond tests

If the same lookup path backs server-side view resolution, a client that commits and immediately queries can read stale state — a read-your-writes violation that would be intermittent and hard to diagnose in production. If the embedded-API path is the only one affected, the fix may just be cache invalidation (or a freshness check against the nameservice head) in the ledger manager's view lookup.

Repro

See the two test files above: drop the db_at_t pinning back to fluree.db(ledger_id) and both tests fail with pre-commit data.

Activity

  1. added
    bug
    on Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions