Skip to content

[engine] suspendFlushAndExecute ownership is first-caller-wins: concurrent callers (backup, verify, snapshot) can observe a resumed flush mid-read #5068

Closed

Description

@lvca

Found and partially fixed during PR #5063 review round 5. PageManagerFlushThread.setSuspended(db, true) is putIfAbsent-based: only the FIRST caller owns the suspension, but suspendFlushAndExecute runs every caller's callback regardless. A concurrent NON-owning caller (a) skips waitForCurrentFlushToComplete, so it can read files while a flush batch is mid-write, and (b) keeps streaming while the owner's exit synchronously flushes the deferred batches - torn reads either way.

PR #5063 serialized the HA snapshot path (SnapshotHttpHandler per-database lock), but the exposure is general across suspension users that can overlap on the same database:

  • SQL BACKUP DATABASE (FullBackupFormat)
  • PostVerifyDatabaseHandler
  • HA snapshot serving (now serialized among themselves, but not against the other two)

Proper fix: refcounted suspension in PageManager - suspend while refcount > 0, resume (and flush deferred) only when the LAST suspender exits; every caller then legitimately owns its window. Needs care with the deferred-RAM backpressure accounting (#4728) and the suspend-owner bookkeeping added in #5012.

Discovered during the 2026-07 audit follow-up (#4962).

Activity

  1. self-assigned this
    on Jul 7, 2026
  2. added theissue type on Jul 7, 2026
  3. added this to the 26.7.2 milestone on Jul 7, 2026
  4. added a commit that references this issue on Jul 7, 2026
  5. lvca commented on Jul 7, 2026

    @lvca
    MemberAuthor

    Fixed in #5074 (merged). Page-flush suspension is now refcounted: every suspendFlushAndExecute caller owns its window - suspension holds while the count is above zero and the resume (Phase-1 flush of the deferred batches) runs only when the LAST suspender exits, so an overlapping backup/verify/snapshot can no longer observe a resumed flush mid-read. Composes with the #4728 deferred-RAM backpressure and the #5012 suspend bookkeeping; the HA SnapshotHttpHandler's per-database lock stays (it also serializes the zip streaming itself). The review round additionally hardened an interrupt-during-wait suspension leak with a deterministic red-first test, and documented the bounded stalled-resume tradeoff against the actual callers.

  6. added a commit that references this issue on Jul 7, 2026
  7. added a commit that references this issue on Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions