8000 BrowserDb (IndexedDB): a failed flush can leave the store with a meta that references missing pages · Issue #894 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

Skip to content

BrowserDb (IndexedDB): a failed flush can leave the store with a meta that references missing pages #894

Open

Description

@adityamukho

Summary

BrowserDb in IndexedDB mode (BrowserDb.open(name)) can store an inconsistent page set after an IndexedDB flush fails: a later successful flush can write a meta page that references pages that never reached IndexedDB. Split out of #441 (comment of 2026-10-07), with further findings from the planning of #441. Branch: v3 (read at 108b993). It is independent of the OPFS mode.

What happens

Each write is a synchronous save() into the in-memory page buffer, followed by an asynchronous IndexedDB transaction with the pages the save dirtied and the keys of the pages it freed.

  1. Dirty pages are lost on failure. take_dirty_pages (src/browser/mod.rs:817) drains the buffer's dirty set before the pages are sent. If write_pages rejects (quota exceeded, transaction aborted), the set is not restored, and the in-memory state has already activated the new meta. The next successful flush sends only its own dirty pages.
  2. Page deletes are lost too. take_flush (:853) releases the freed pages' bytes and builds the delete list before the write. BrowserBufferBackend::release (src/browser/buffer.rs:68) reports a page once, so a retry produces no delete for it. This matters most for an importGraph() of a smaller database.
  3. Every write path is affected: execute (apply_write, :478), BrowserWriteTransaction.commit() (:552), checkpoint() (:231), importGraph() (:325; it swaps the live store before the flush is awaited) and the migration flush in open (:121).
  4. Overlapping calls. The RefCell borrow is released before each IndexedDB await, and commit() clears tx_open before the flush. A later operation can compute its page delta before an earlier flush has failed, so restoring dirty ids after the error is not enough: the later flush can already be queued and succeed.
  5. Some failures may never settle. transaction_to_promise (src/browser/indexeddb.rs:38) listens for complete and error but not abort. An abort need not fire a request error event (IndexedDB "abort a transaction"), so a commit-time abort can leave the promise pending. write_pages (:168) can also return early from a failed put/delete call without aborting the transaction it has already queued requests on.

src/browser/tx_tests.rs:272 pins today's contract for a failed flush: the call rejects, the facts stay visible in memory, and a reopen shows the previous stored state. That test does not cover a later successful flush.

Expected

  • After a failed flush, a later successful write or checkpoint() stores the complete state it acknowledges: every page the stored meta references is in IndexedDB, and every freed page's key is deleted. A reopen matches that state.
  • A stale retry never overwrites a newer page or deletes a page id that has been reused.
  • Overlapping calls are ordered or rejected; none resolves over missing predecessor pages.
  • An aborted transaction rejects; a failed request cannot leave a partly committed flush.
  • Whether a rejected write stays visible in memory is unchanged unless decided otherwise.

Tests wanted

Failed flush then success for execute, commit(), checkpoint() and a smaller-file importGraph(); repeated failures; page-id reuse between the failure and the retry; an overlapping call behind a failing flush; an abort-only failure settling. A recoverable abort is needed as well as the closed-connection case the existing test uses.

Notes

Activity

  1. added this to the v3.0.0 milestone on Nov 14, 2026
  2. adityamukho commented on Nov 17, 2026

    @adityamukho
    CollaboratorAuthor

    Confirmed end-to-end on v2.x by #896 (report, harness on branch spike/896-idb-flush-repro).

    Affected (tested): v2.0.11 source, current main (19fd080a6), and the published @minigraf/browser@2.0.11. By source only: the flush pattern (drain the dirty set, then await write_pages, with no restore on failure) has been in BrowserDb since it was added in #149 (first released in v0.20.0). Releases before v2.0.11 were not run.

    • Realistic trigger. A QuotaExceededError commit abort leaves the write's promise pending forever. A later write is acknowledged, and the database then fails to open with [INT-052] Page 6 not found. A rejected multi-page write followed by a successful write has the same effect.
    • Also confirmed: checkpoint() succeeds without retrying a failed flush; a rejected write or import stays visible in memory; a synchronous put throw commits the puts already queued (synthetic); and Closure::once on the transaction's onerror throws FnOnce called more than once on every request-abort.

    Labelled known-issue and added to #421. v3 behaviour still needs its own pinned-build run here.

  3. added
    known-issueBug present in a published release and not yet fixed in one; listed in the pinned known-issues issue
    on Nov 17, 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

    bugSomething isn't workingdata-integrityData integrity issueknown-issueBug present in a published release and not yet fixed in one; listed in the pinned known-issues issue

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0