Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

BLiteSession.Rollback() does not await the rollback: it returns while the transaction is still active, and failures go unobserved

Open
#307 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

@CaffeinatedCoder is already working on this.

Since Oct 18, 2026.

  • #316 by @CaffeinatedCoder — open

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
csharp
Domain
databases

Research direction

Start with src/BLite.Core/BLiteSession.cs:107-116, then trace CurrentTransaction.RollbackAsync() through src/BLite.Core/Transactions/Transaction.cs:135-152 and the rollback handlers in DocumentCollection.cs and DynamicCollection.cs. Reproduce the concurrent rollback scenario and add coverage verifying that the transaction is Aborted when the operation returns and that WAL-write failures propagate; update the README session sample if the public API changes. Use the existing transaction and storage test structure to locate the appropriate tests.

Written by the indexing model from the issue text.

Description

bug package/core severity/medium

BLiteSession.Rollback() starts CurrentTransaction.RollbackAsync() and returns without awaiting it. The session forgets the transaction at once, but the rollback finishes later: the abort record is written to the WAL, then the transaction becomes Aborted and its rollback handlers run, which restore the collection's free-space index. Any exception from that work is never observed.

The README's session sample uses exactly this call in its catch block.

Found while reviewing the public API for #296.

Repro

using var engine = new BLiteEngine("rb.db");
var col = engine.GetOrCreateCollection("orders");
// background load: another task inserting into a second collection in a loop
for (int i = 0; i < 300; i++)
{
    using var session = engine.OpenSession();
    var tx = session.BeginTransaction();
    await session.InsertAsync("orders", doc);
    session.Rollback();
    if (tx.State != TransactionState.Aborted) stillActive++;
}
// stillActive: 59–85 of 300 across five runs; 0 of 200 without the background load

The rolled-back documents do not appear (the transaction's page images are dropped synchronously), so no data was lost in these runs. What is late is the rest of the rollback: the abort record, the state change and the free-space-index restore (_fsi.RollbackTransaction), which the next insert on that collection may read before it happens.

Expected: when Rollback() returns, the rollback is complete, and a failure is thrown to the caller.

Actual: under contention, about one rollback in four is still running when Rollback() returns, and its exceptions are lost.

Where in the code (0450b97)

  • BLiteSession.Rollback() (src/BLite.Core/BLiteSession.cs:107-116): try { CurrentTransaction.RollbackAsync(); } finally { CurrentTransaction = null; }, a ValueTask dropped without await.
  • Transaction.RollbackAsync awaits _storage.RollbackTransactionAsync (WAL abort record) before it sets Aborted and runs OnRollback (src/BLite.Core/Transactions/Transaction.cs:135-152).
  • The handlers restore the free-space index (src/BLite.Core/Collections/DocumentCollection.cs:4306, src/BLite.Core/DynamicCollection.cs:2709).
  • For comparison, Transaction.Dispose blocks on the same call (RollbackAsync().GetAwaiter().GetResult(), Transaction.cs:189), and BLiteEngine.Rollback() is a documented no-op (src/BLite.Core/BLiteEngine.cs:432-438).

Suggested fix

  • Add BLiteSession.RollbackAsync(CancellationToken) that awaits, and make Rollback() either block on it (as Transaction.Dispose does) or mark it [Obsolete] in favour of the async one; update the README sample to await session.RollbackAsync().
  • In v6, drop the synchronous Rollback() and the no-op BLiteEngine.Rollback() / CommitAsync() (#296, public API).
  • Test: under concurrent commits, after Rollback() (or RollbackAsync()) returns, the transaction is Aborted; and a rollback whose WAL write throws surfaces the exception.

Related: #296.

Dominant language
C#
Stars
66
Forks
6
Avg merge
1d 2h
Merged PRs (30d)
58

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from EntglDb/BLite

All issues in EntglDb/BLite

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.