#3035·LiteDB

Strengthen exclusive recovery ownership across rebuild construction and installation

Author: JKamskerCreated Sep 28, 2026Updated Sep 28, 2026

A Direct opener can potentially enter between rebuild finishing its source scan and publishing the installation marker. Track an exclusive recovery claim spanning source inspection, replacement construction, installation/rollback and handoff to the reopened engine.

Raised in the re-review of PR #3025. The reviewer explicitly classified this as a separate hardening follow-up: Shared/Coordinated operations hold their mutex, and concurrent Direct connections are not the supported multi-process mode. This does not reopen #3022's corruption-classification or cleanup-error blocker.

Code-inspection evidence at 3ff1fbbee04364f1f152d93e02281c5a6b76bba6:

  • BuildReplacement disposes its source FileReaderV8 before returning to Rebuild.
  • Rebuild then calls Install, which creates the -rebuild marker before its first rename.
  • EnsureAvailable checks for that marker during opening. Before marker creation, it does not convey an exclusive rebuild claim.

A competing Direct writer could open and acknowledge a commit after the candidate's contents have been fixed. Installation could then publish the older candidate; Unix rename semantics deserve particular coverage. This is a code-inspection hypothesis, not a confirmed process-level data-loss reproduction.

Suggested deterministic reproduction:

  1. Create a healthy file with committed records, including unrelated collections and a nonempty WAL; test plain and encrypted variants.
  2. Start explicit Rebuild in process A. Pause at SimulateInstallFailure("before-recovery-marker"), after source-reader disposal and before marker publication.
  3. Have process B open the same path in Direct mode and attempt a durable insert. Record separately whether opening succeeds and whether the insert is acknowledged.
  4. Resume A, reopen the canonical database, and compare records and backups against the acknowledged-state model. Exercise both B closing before installation and retaining its handle through installation.

Acceptance criteria for the follow-up:

  • An exclusive claim bridges source acquisition, build, install/rollback and engine handoff; a competing opener cannot slip between a marker check and acquiring the database handle.
  • Denied admission leaves data/WAL/backup bytes unchanged and returns a clear error or bounded wait.
  • Repeated process death, failed claim acquisition/release, partial marker writes and installation/rollback failures retain a complete original or replacement state and do not leave an unrecoverable stale ownership claim.
  • Independent-process tests cover Direct contention plus Shared/Coordinated regressions on Windows and Unix; verify original and unrelated records, acknowledged concurrent writes, backup pairs and repeated reopen.
  • Define behavior for read-only opens, path aliases, caller-owned streams, unsupported file-locking environments and older binaries. Preserve the existing durable -rebuild marker's incomplete-installation protection.