Skip to content

Collection-per-file mode: concurrent explicit transactions corrupt the free-space index (IndexOutOfRangeException in SnapshotForTransaction) #325

Open

Description

@mrdevrobot

Summary

In collection-per-file mode (CollectionDataDirectory), concurrent explicit transactions on one collection throw IndexOutOfRangeException from FreeSpaceIndex.SnapshotForTransaction (src/BLite.Core/Storage/FreeSpaceIndex.cs ~191). The free-space index's Dictionary is mutated concurrently and left inconsistent.

Cause

In that mode the free-space index is used without its _gate, and its OnCommit/OnRollback handlers run outside the collection lock, so two transactions read and write the same Dictionary at once.

Repro

8 writers × 50 explicit transactions (begin, insert, commit) into one collection of an engine opened with CollectionDataDirectory: 20 of 400 transactions throw IndexOutOfRangeException on main 3648a02. Single-file mode is not affected. Found during the review of #310, which does not cause it (6–37 of 400 with that PR applied).

Expected

No exception; the free-space index is updated under the same synchronisation as in single-file mode.

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 workingpackage/coreAffects BLite.Coreseverity/mediumSpace leak, inconsistency or failure in a narrow scenariotriage

    Type

    No type

    Projects

    • Status
      Todo

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions